3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php public static function setKey($sessionKeys, $value) { $currentKey = ''; $counter = 0; $prevStep = $_SESSION; try { $sessionKeysArray = explode(':', $sessionKeys); foreach ($sessionKeysArray as $key) { $counter++; $currentKey .= '[\'' . $key . '\']'; if (array_key_exists($key, $prevStep)) { eval('$prevStep = $_SESSION' . $currentKey . ';'); if (!is_array($prevStep) && count($sessionKeysArray) > $counter) { throw new Exception ("\$_SESSION$currentKey is not an array"); } else if (count($sessionKeysArray) == $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 v2q6p
Output for 7.0.0 - 7.0.2
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in /in/RVpWV 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/RVpWV 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/RVpWV on line 3
Process exited with code 255.