3v4l.org

run code in 300+ PHP versions simultaneously
<?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 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 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 } } } }

preferences:
206.87 ms | 1397 KiB | 110 Q