1.2.1078. Scope Resolution Operator¶
The scope resolution operator ::class is faster than a call to get_class() function.
It is also possible to replace get_class() by static::class to get the name of the calling class.
<?php
$a = new stdClass();
echo $a::class;
// identical to
echo get_class($a);
class x {
function foo() { echo static::class; }
}
class y extends x {}
// static will resolve to y here
(new y)->foo();
?>
See also get_class..
1.2.1078.1. Connex PHP features¶
1.2.1078.1.1. Suggestions¶
Use the ::class operator instead of the call to get_class()
1.2.1078.1.2. Specs¶
Short name |
Performances/ClassOperator |
Rulesets |
|
Exakat since |
2.3.3 |
PHP Version |
With PHP 7.0 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |