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 getParent() { return $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 =& Item::newWithParent($item); break; } } while (true); var_dump($item);
Output for 5.4.0 - 5.4.15
Parse error: syntax error, unexpected 'getParent' (T_STRING), expecting variable (T_VARIABLE) in 8f3H6 on line 13
Process exited with code 255.
Output for 5.3.25
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/lPFef on line 13
Process exited with code 255.
Output for 5.3.0 - 5.3.24
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in 8f3H6 on line 13
Process exited with code 255.

preferences:
177.15 ms | 1395 KiB | 49 Q