3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MenuLinkTreeElement { public $link; public $subtree; public $depth; public $hasChildren; public $inActiveTrail; public $access; public $options; public function __construct($link, $has_children, $depth, $in_active_trail, array $subtree) { $this->link = $link; $this->hasChildren = $has_children; $this->depth = $depth; $this->subtree = $subtree; $this->inActiveTrail = $in_active_trail; $this->access = NULL; $this->options = array(); } public function count() { $sum = function ($carry, MenuLinkTreeElement $element) { return $carry + $element->count(); }; return 1 + array_reduce($this->subtree, $sum); } } // Arrays. $memory_before = memory_get_usage(); $array_start = microtime(TRUE); $storage = array(); for ($i = 0; $i < 1000; $i++) { $storage[] = array( 'link' => new StdClass(), 'has_children' => TRUE, 'depth' => 3, 'in_active_trail' => FALSE, 'below' => array(), 'access' => NULL, 'options' => array(), ); } $array_time = microtime(TRUE) - $array_start; $array_memory = memory_get_usage() - $memory_before; unset($storage); // Objects. $memory_before = memory_get_usage(); $object_start = microtime(TRUE); $storage = array(); for ($i = 0; $i < 1000; $i++) { $storage[] = new MenuLinkTreeElement(new StdClass(), TRUE, 3, FALSE, array()); } $object_time = microtime(TRUE) - $object_start; $object_memory = memory_get_usage() - $memory_before; unset($storage); echo 'arrays: ' . number_format($array_time, 3) . ' s, ' . ($array_memory/1024) . " KB\n"; echo 'objects: ' . number_format($object_time, 3) . ' s, ' . ($object_memory/1024) . " KB\n";
Output for 7.1.0
arrays: 0.000 s, 442.3046875 KB objects: 0.000 s, 239.3671875 KB
Output for 7.0.0 - 7.0.5, 7.0.7 - 7.0.8, 7.0.10 - 7.0.14
arrays: 0.000 s, 551.6796875 KB objects: 0.000 s, 348.7421875 KB
Output for 7.0.6, 7.0.9
arrays: 0.000 s, 551.6796875 KB objects: 0.001 s, 348.7421875 KB
Output for 5.6.0 - 5.6.3, 5.6.5 - 5.6.20, 5.6.22 - 5.6.23, 5.6.28
arrays: 0.001 s, 1454.2421875 KB objects: 0.001 s, 869.5859375 KB
Output for 5.6.21, 5.6.24 - 5.6.25
arrays: 0.002 s, 1454.2421875 KB objects: 0.001 s, 869.5859375 KB
Output for 5.6.4
arrays: 0.002 s, 1454.2421875 KB objects: 0.002 s, 869.5859375 KB
Output for 5.5.4, 5.5.6, 5.5.37 - 5.5.38
arrays: 0.002 s, 1454.25 KB objects: 0.001 s, 869.5546875 KB
Output for 5.5.0 - 5.5.3, 5.5.5, 5.5.7 - 5.5.36
arrays: 0.001 s, 1454.25 KB objects: 0.001 s, 869.5546875 KB
Output for 5.4.10 - 5.4.13, 5.4.15 - 5.4.17, 5.4.19 - 5.4.20, 5.4.22 - 5.4.23, 5.4.25 - 5.4.36, 5.4.38 - 5.4.45
arrays: 0.001 s, 1454.2109375 KB objects: 0.001 s, 869.5078125 KB
Output for 5.4.14, 5.4.18, 5.4.21, 5.4.24, 5.4.37
arrays: 0.002 s, 1454.2109375 KB objects: 0.001 s, 869.5078125 KB
Output for 5.4.0, 5.4.2, 5.4.4 - 5.4.6, 5.4.9
arrays: 0.001 s, 1454.234375 KB objects: 0.001 s, 869.5546875 KB
Output for 5.4.1, 5.4.3, 5.4.7 - 5.4.8
arrays: 0.002 s, 1454.234375 KB objects: 0.001 s, 869.5546875 KB
Output for 5.3.16 - 5.3.17, 5.3.28 - 5.3.29
arrays: 0.001 s, 1837.234375 KB objects: 0.001 s, 1939.9453125 KB
Output for 5.3.11 - 5.3.13, 5.3.15, 5.3.18, 5.3.20, 5.3.23 - 5.3.27
arrays: 0.002 s, 1837.234375 KB objects: 0.002 s, 1939.9453125 KB
Output for 5.3.19, 5.3.21 - 5.3.22
arrays: 0.001 s, 1837.234375 KB objects: 0.002 s, 1939.9453125 KB
Output for 5.3.14
arrays: 0.002 s, 1837.234375 KB objects: 0.003 s, 1939.9453125 KB
Output for 5.3.1, 5.3.3 - 5.3.10
arrays: 0.002 s, 1837.2578125 KB objects: 0.002 s, 1939.9765625 KB
Output for 5.3.2
arrays: 0.002 s, 1837.2578125 KB objects: 0.003 s, 1939.9765625 KB
Output for 5.3.0
arrays: 0.001 s, 1837.2578125 KB objects: 0.001 s, 1939.9765625 KB
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/XcfvE on line 24
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/XcfvE on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XcfvE on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/XcfvE on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/XcfvE on line 4
Process exited with code 255.