1.2.1061. 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.1061.1. Suggestions

  • Use the ::class operator instead of the call to get_class()

1.2.1061.2. Specs

Short name

Performances/ClassOperator

Rulesets

All, Changed Behavior, Performances

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

Features

scope-resolution-operator, static

Available in

Entreprise Edition, Exakat Cloud