1.2.1654. self, parent, static Outside Class¶
self, parent and static should be called inside a class or trait. PHP lint won’t report those situations.
self, parent and static may be used in a trait : their actual value will be only known at execution time, when the trait is used.
Such syntax problem is only revealed at execution time : PHP raises a Fatal error.
The origin of the problem is usually a method that was moved outside a class, at least temporarily.
Closures and arrow functions are reported here, though they might be rebound with a valid context before execution.
<?php
// In the examples, self, parent and static may be used interchangeably
// This raises a Fatal error
//Fatal error: Uncaught Error: Cannot access static:: when no class scope is active
new static();
// static calls
echo self::CONSTANTE;
echo self::$property;
echo self::method();
// as a type hint
function foo(static $x) {
doSomething();
}
// as a instanceof
if ($x instanceof static) {
doSomething();
}
?>
See also Scope Resolution Operator (::).
1.2.1654.2. Connex PHP features¶
1.2.1654.2.1. Suggestions¶
Remove the call to static, parent or self
Make sure the closure is correctly binded before usage
1.2.1654.2.2. Specs¶
Short name |
Classes/NoPSSOutsideClass |
Rulesets |
|
Exakat since |
0.10.3 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Note |
This issue may lint but will not run |
Available in |