self:: should always refer to the class in which it is used (note that the behavior of PHP 5 is also incorrect.)
This was a bug , fixed in 7.1.4 , which applies to the resolution of self:: and parent:: only inside class constants.
Mostly in:
const B = self::A . self::C;
self::C is not yet known, and permission is delayed. At the point of possible resolution, unfortunately, the proper volume was lost.
The problem is also more subtle than just basic and extended, as you can get the value from another expanding class. For example:.
https://3v4l.org/cY1I0
class A { const selfN = self::N; const N = 'A'; } class B extends A { const N = 'B'; } class C extends A { const N = 'C'; } var_dump(B::selfN);
In PHP 7.0.0 - 7.1.3 this produces:
string(1) "B" string(1) "B"
Although if you change it to:
https://3v4l.org/RltQj
var_dump(C::selfN);
You'll get:
string(1) "C" string(1) "C"
To avoid this in the affected versions, use the class name, not self:: in the class constant definitions, for example. const selfN = A::N
Paul crovella
source share