1.2.1263. Undefined static ::class¶
The \:\:class
operator provides the full name of the class, enumeration, trait or interface. \:\:class
doesn’t check if the corresponding class exists.
\:\:class
must be checked with a call to class_exists(). Otherwise, it may lead to a Class 'foo' not found
or even silent dead code : this happens also with Catch and instanceof commands with undefined classes. PHP doesn’t raise an error in that case.
<?php
class foo() {}
// prints foo
echo foo::class;
// prints bar though bar doesn't exist.
echo bar::class;
?>
See also Class Constants.
1.2.1263.2. Connex PHP features¶
1.2.1263.2.1. Suggestions¶
Create the missing class
Fix the name part of the syntax
Check the name part of syntax with class_exists()
1.2.1263.2.2. Specs¶
Short name |
Classes/UndefinedStaticclass |
Rulesets |
|
Exakat since |
1.3.5 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |