[php-src] Issue #10935: trait代码复 用机制问题

From: Date: Sat, 25 Mar 2023 15:58:48 +0000
Subject: [php-src] Issue #10935: trait代码复 用机制问题
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244005@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10935 Author: vscing ### Description The following code: ```php <?php class A { protected static $instance = null; public static function getInstance(...$args) { if(!isset(self::$instance)){ self::$instance = new static(...$args); } return self::$instance; } public function getB() { return B::class::getInstance(); } } class B extends A { protected static $instance = null; public static function getInstance(...$args) { if(!isset(self::$instance)){ self::$instance = new static(...$args); } return self::$instance; } } var_dump(A::getInstance()->getB()); // B ``` Resulted in this output: ``` <?php trait Singleton { protected static $instance = null; public static function getInstance(...$args) { if(!isset(self::$instance)){ self::$instance = new static(...$args); } return self::$instance; } } class A { use Singleton; public function getB() { return B::class::getInstance(); } } class B extends A { use Singleton; } var_dump(A::getInstance()->getB()); // A ``` But I expected this output instead: ``` var_dump(A::getInstance()->getB()); // B ``` ### PHP Version PHP 8.2.3 ### Operating System mac 13.0.1

« previous php.bugs (#244005) next »