3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Node { public $data = null; public $parent = null; public $left = null; public $right = null; } function mirror_recursive($root) { if ($root === null) { return; } mirror_recursive($root->left); mirror_recursive($root->right); $temp = $root->left; $root->left = $root->right; $root->right = $temp; } function mirror_norec($root) { $queue = array(); array_unshift($queue, $root); while (!empty($queue)) { $cnode = array_pop($queue); if ($cnode->left !== null) array_unshift($queue, $cnode->left); if ($cnode->right !== null) array_unshift($queue, $cnode->right); $temp = $cnode->left; $cnode->left = $cnode->right; $cnode->right = $temp; } } function inorder_traverse($root) { if ($root->left !== null) inorder_traverse($root->left); echo $root->data . " "; if ($root->right !== null) inorder_traverse($root->right); } $root = new Node(); $n1 = new Node(); $n2 = new Node(); $n11 = new Node(); $n12 = new Node(); $n13 = new Node(); $n14 = new Node(); $n15 = new Node(); $n21 = new Node(); $root->data = 0; $n1->data = 1; $n2->data = 2; $n11->data = 11; $n12->data = 12; $n13->data = 13; $n14->data = 14; $n15->data = 15; $n21->data = 21; $root->left = $n1; $root->right = $n2; $n1->left = $n11; $n1->right = $n12; $n11->left = $n13; $n12->right = $n14; $n13->left = $n15; $n2->right = $n21; inorder_traverse($root); echo "<br>"; mirror_recursive($root); inorder_traverse($root); echo "<br>"; mirror_norec($root); inorder_traverse($root); ?>
Output for 5.0.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
15 13 11 1 12 14 0 2 21 <br>21 2 0 14 12 1 11 13 15 <br>15 13 11 1 12 14 0 2 21
Output for hhvm-3.10.0

Process exited with code 153.
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/OpNUP on line 5
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/OpNUP on line 5
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/OpNUP on line 5
Process exited with code 255.