Anonymous Class Name Includes Extends¶
The fully qualified name of an anonymous class (sic) includes the parent class as the first part of the name, since PHP 8.0.
In previous versions, it only used class
.
It also includes the mention anonymous
, the name of the file and the line number. The parent name is the fully qualified name, so it includes the namespace, except for the initial backaslash (hence, here, it is not displayed).
PHP code¶
<?php
$object = new class() extends \Exception {};
echo get_class($object);
Before¶
class@anonymous/codes/anonymousSignature.php:3
After¶
Exception@anonymous/codes/anonymousSignature.php:3
PHP version change¶
This behavior changed in 8.0