3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php public static function setKey($sessionKeys, $value) { $currentKey = ''; $counter = 0; $prevStep = $_SESSION; try { $session_keys_array = explode(':', $sessionKeys); foreach ($session_keys_array as $key) { $counter++; $currentKey .= '[\'' . $key . '\']'; if (array_key_exists($key, $prevStep)) { eval('$prevStep = $_SESSION' . $currentKey . ';'); if (!is_array($prevStep) && count($session_keys_array) > $counter) { throw new Exception ("\$_SESSION$currentKey is not an array"); } else if (count($session_keys_array) == $counter) { eval('$_SESSION' . $currentKey . ' = ' . $value . ';'); } } else if (is_array($prevStep) && count($session_keys_array) == $counter){ eval('$_SESSION' . $currentKey . ' = ' . $value . ';'); } } eval('var_dump($_SESSION' . $currentKey . ');'); } catch (Exception $e) { return false; } return eval('!empty($_SESSION' . $currentKey . ');'); } $_SESSION['1']['2']['3'] = 'zzzz'; setKey('1:2:3', 77);
based on RVpWV
Output for 7.0.0 - 7.0.2
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /in/2l4T9 on line 3
Process exited with code 255.
Output for 5.4.11 - 5.6.17
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /in/2l4T9 on line 3
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected T_PUBLIC in /in/2l4T9 on line 3
Process exited with code 255.