Bug #77985 [NEW]: Wrong resolution of "Late Static Binding" after static::method()

From: Date: Tue, 07 May 2019 19:31:40 +0000
Subject: Bug #77985 [NEW]: Wrong resolution of "Late Static Binding" after static::method()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220754@lists.php.net to get a copy of this message
From: dev at mabe dot berlin Operating system: Linux PHP version: Irrelevant Package: Class/Object related Bug Type: Bug Bug description:Wrong resolution of "Late Static Binding" after static::method() Description: ------------ Wrong resolution of the referenced class that was initially called (Late Static Binding) if it gets called using static::method(). Both, static::class as well as get_called_class() result into the wrong class name. Simplified explanation from test script: 1. calling "B:call()" 2. -> calling "self::getStaticClass()" defined in "A::call" This should get resolved to "A::getStaticClass()" 3. -> returning "static::class" This should get resolved to "A:class" as it was called by "A::getStaticClass()" Test script: --------------- <?php class A { static function getStaticClass(){ return static::class; } static function getCalledClass() { return get_called_class(); } static function call(){ $self = self::class; echo $self; echo $self::getStaticClass(); echo $self::getCalledClass(); echo self::getStaticClass(); echo self::getCalledClass(); echo PHP_EOL; $static = static::class; echo $static; echo $static::getStaticClass(); echo $static::getCalledClass(); echo static::getStaticClass(); echo static::getCalledClass(); echo PHP_EOL; $calledClass = get_called_class(); echo $calledClass; echo $calledClass::getStaticClass(); echo $calledClass::getCalledClass(); echo PHP_EOL; } } class B extends A {} echo 'A:call()', PHP_EOL; A::call(); echo 'B:call()', PHP_EOL; B::call(); Expected result: ---------------- A:call() AAAAA AAAAA AAA B:call() AAAAA BBBBB BBB Actual result: -------------- A:call() AAAAA AAAAA AAA B:call() AAABB <- The last two cases should resolve to A instead of B BBBBB BBB -- Edit bug report at https://bugs.php.net/bug.php?id=77985&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77985&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77985&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77985&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77985&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77985&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77985&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77985&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77985&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77985&r=support Expected behavior: https://bugs.php.net/fix.php?id=77985&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77985&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77985&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77985&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77985&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77985&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77985&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77985&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77985&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77985&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77985&r=mysqlcfg

« previous php.bugs (#220754) next »