1.2.959. Parent, Static Or Self Outside Class¶
PHP 7.0 and later detect some of their usage at compile time, and emits a fatal error. Static may be used in a function or a closure <https://www.php.net/`closure>`_, but not globally.
<?php
class x {
const Y = 1;
function foo() {
// self is \x
echo self::Y;
}
}
const Z = 1;
// This lint but won't anymore
echo self::Z;
?>
1.2.959.1. Suggestions¶
Make sure the keyword is inside a class context
1.2.959.2. Specs¶
Short name |
Classes/PssWithoutClass |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Changed Behavior |
PHP 7.0 - More |
Precision |
Very high |
Features |
parent, self, static, class |
Available in |