3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Item { public static function newWithParent(Item $parent) { $item = new Item(); $item->parent = $parent; return $item; } private $parent; public function getParent() { return $this->parent; } } $item = Item::newWithParent(Item::newWithParent(Item::newWithParent(new Item()))); // Basically it's this now: {"parent":{"parent":{"parent":{"parent":null}}}} // I want to set that null value $current = $item; do { $current =& $current->getParent(); if ($current->getParent() === null) { $current =& new Item(); break; } } while (true); var_dump($item);
Output for hhvm-3.10.0 - 3.12.0
object(Item)#4 (1) { ["parent":"Item":private]=> object(Item)#3 (1) { ["parent":"Item":private]=> object(Item)#2 (1) { ["parent":"Item":private]=> object(Item)#1 (1) { ["parent":"Item":private]=> NULL } } } }
Output for 5.3.0 - 5.6.28
Deprecated: Assigning the return value of new by reference is deprecated in /in/qD3Eb on line 26 Strict Standards: Only variables should be assigned by reference in /in/qD3Eb on line 24 Strict Standards: Only variables should be assigned by reference in /in/qD3Eb on line 24 Strict Standards: Only variables should be assigned by reference in /in/qD3Eb on line 24 object(Item)#4 (1) { ["parent":"Item":private]=> object(Item)#3 (1) { ["parent":"Item":private]=> object(Item)#2 (1) { ["parent":"Item":private]=> object(Item)#1 (1) { ["parent":"Item":private]=> NULL } } } }