This is expected behaviour given my understanding of how late static binding works:
If there is a chain of “self::” calls that ultimately ends in “static::someMethod”, then PHP behaves as if every preceding call was a call to “static::”, not “self::”. In your second call you’re explicitly overriding that resolution by changing using (self::class)::someMethod, which PHP always treats as A::someMethod, thus producing the expected output. > On Mar 8, 2020, at 4:48 AM, Marc <marc@mabe.berlin> wrote: > > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php