3v4l.org

run code in 300+ PHP versions simultaneously
<?php class a { var $me='hello'; function __construct() { $b = b::kill(); var_dump($b); /* object(b)#2 (1) { ["killerMessage"]=> string(5) "Oops!" } */ return $b; } } class b { var $killerMessage=null; function __construct() { $this->killerMessage = 'Oops!'; return $this; } static function kill() { return new b; } } $a= new a; var_dump($a); /* object(a)#1 (1) { ["me"]=> string(5) "hello" } */ //-------------------------------------- //CurrentResult: //php -f test.php //object(b)#2 (1) { // ["killerMessage"]=> // string(5) "Oops!" //} //object(a)#1 (1) { // ["me"]=> // string(5) "hello" //} //-------------------------------------- //ExpectedOutput: //object(b)#2 (1) { // ["killerMessage"]=> // string(5) "Oops!" //} //object(b)#2 (1) { // ["killerMessage"]=> // string(5) "Oops!" //} ?>

preferences:
30.04 ms | 402 KiB | 5 Q