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 $list = $item; do { $prev = &$item; $item = $item->getParent(); if ($item->getParent() === null) { $prev =& Item::newWithParent($item); break; } } while (true); var_dump($list);
Output for 5.3.0 - 5.3.24, 5.4.0 - 5.4.15
Parse error: syntax error, unexpected '&' in JZuCC on line 15
Process exited with code 255.
Output for 5.3.25
Parse error: syntax error, unexpected '&' in /in/EQ8Pn on line 15
Process exited with code 255.

preferences:
182.05 ms | 1386 KiB | 49 Q