1.2.1239. Undefined ::class¶
\:\:class
doesn’t check if a 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.1239.1. Suggestions¶
Create the missing class
Fix the name part of the syntax
Check the name part of syntax with class_exists()
1.2.1239.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 |
Features |
class |
Available in |