Re: Bug Wrong resolution of "Late Static Binding" after self::method()
| From: | Rowan Tommins | Date: | Sun, 08 Mar 2020 11:14:03 +0000 |
| Subject: | Re: Bug Wrong resolution of "Late Static Binding" after self::method() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108896@lists.php.net to get a copy of this message | ||
On 8 March 2020 09:47:37 GMT+00:00, Marc <marc@mabe.berlin> wrote:
>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"
Someone else may be able to confirm if this is a bug or working as designed, but what seems to be
happening is that the value of "static" is not reset when calling a method using self::
This doesn't just apply to getting the class name, but to actual static calls; for instance:
# https://3v4l.org/p2g8E
class A {
static function call() {
self::method1();
}
static function method1() {
static::method2();
}
static function method2() {
echo 'Base definition';
}
}
class B extends A {
static function method2() {
echo 'Override';
}
}
B::call();
If the call to self::method1() reset the called class, this would run A::method2() and echo
'Base definition'; instead, the called class is remembered, and it calls B::method2() and
echoes 'Override'.
If you explicitly call A::method1(), as you are effectively doing in your self::class example, the
"called class" information is reset, and the call goes through to A::method2().
Regards,
Hi Marc,
--
Rowan Tommins
[IMSoP]