Bug Wrong resolution of "Late Static Binding" after self::method()
| From: | Marc | Date: | Sun, 08 Mar 2020 09:47:37 +0000 |
| Subject: | Bug Wrong resolution of "Late Static Binding" after self::method() | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-108895@lists.php.net to get a copy of this message | ||
Hi,
I have reported a bug in Mai 2019 but did not get any response here https://bugs.php.net/bug.php?id=77985.
The problem is that "static::class" as well as "get_called_class()" used within a method resolves to a different class if this method was called with "self::method". Interestingly it works as expected if the method got called with "ClassName::method".
I send it here because fixing this could result in a hard to find BC break and it could be a good idea to handle this in 8.0.
https://3v4l.org/NSdB8
class A {
static function call() {
self::method();
$self = self::class;
$self::method();
}
static function method() { echo static::class; }
}
class B extends A {}
B::call(); // displays "BA" instead of "AA"
In case this is "Not a Bug" please explain to me why the result of "self::method()" is different then "$self = self::class; $self::method();".
Thanks,
Marc