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 do { $item = $item->getParent(); if ($item->getParent() === null) { $item =& new Item(); break; } } while (true); var_dump($item);
Output for hhvm-3.10.0 - 3.12.0
object(Item)#2 (1) { ["parent":"Item":private]=> NULL }
Output for 5.3.25, 5.3.27 - 5.3.29, 5.4.18 - 5.6.28
Deprecated: Assigning the return value of new by reference is deprecated in /in/rFRLl on line 25 object(Item)#2 (1) { ["parent":"Item":private]=> NULL }
Output for 5.3.0 - 5.3.24, 5.3.26, 5.4.0 - 5.4.17
Deprecated: Assigning the return value of new by reference is deprecated in /in/5oBu0 on line 25 object(Item)#2 (1) { ["parent":"Item":private]=> NULL }