3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { public function doSomething(array $a) { $data = array(); if (array_key_exists('a', $a)) { $data[] = 'Hello ' . $a['a']; } if (array_key_exists('b', $a)) { $data[] = ' ' . $a['b']; } if (array_key_exists('c', $a)) { $data[] = $a['c']; } if (array_key_exists('d', $a)) { $data[] = 'bar'.$a['d']; } if (array_key_exists('f', $a)) { $data[] = ' tue' . $a['f']; } return $data; } public function DoSameThing(array $a) { $data = array(); foreach ($a as $k => $v) { switch ($k) { case 'a': $data[] = 'Hello ' . $v; break; case 'b': $data[] = ' ' . $v; break; case 'c': $data[] = $v; break; case 'd': $data[] = 'bar' . $v; break; case 'f': $data[] = ' tue' . $v; break; } } return $data; } } $foo = new Foo; echo implode( ' ', $foo->doSomething( array( 'a' => 'John', 'b' => 'is happy', 'c' => ' and ', 'd' => 'bie', 'e' => 'Hello world', 'f' => ' rick', ) ) ); echo "\n"; echo implode( ' ', $foo->doSamething( array( 'a' => 'John', 'b' => 'is happy', 'c' => ' and ', 'd' => 'bie', 'e' => 'Hello world', 'f' => ' rick', ) ) );
Output for 5.1.0 - 7.2.0
Hello John is happy and barbie tue rick Hello John is happy and barbie tue rick
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/JFIoV on line 4
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/JFIoV 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/JFIoV 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/JFIoV on line 4
Process exited with code 255.