1.2.965. Parent Is Not Static¶
The parent keyword behaves like self, not like static. It links to the parent of the defining expression, not to the one being called.
This may skip the parent of the calling class, and create a Undefined method call, or yield the wrong ::class value. It may also skip a local version of the method.
<?php
class w {
}
class x extends w {
function foo() {
parent::method();
}
// method() is in the parent of Y, but not in the one of X.
function method() {
print __METHOD__;
}
}
class y extends x {}
(new y)->foo();
// print W::method
(new y)->method();
// print x::method
?>
1.2.965.1. Connex PHP features¶
1.2.965.1.1. Suggestions¶
Use self keyword
Use static keyword
Use hard-coded class name keyword
1.2.965.1.2. Specs¶
Short name |
Classes/ParentIsNotStatic |
Rulesets |
|
Exakat since |
2.4.3 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |