3v4l.org

run code in 300+ PHP versions simultaneously
<?php function setSessionTestingData() { $agent = new Agent(); $ticket = new Ticket(); $_SESSION = array( 'agent_id' => '2', 'ticket_id' => '3', 'agent' => $agent, 'ticket' => $ticket, 'sub_array' => array( 'sub' => 4, 'agent' => $agent, 'ticket' => $ticket, ), ); return $_SESSION; } function getKey($session_key, $is_object_of_type = null) { $current_key = ''; $counter = 0; try { $session_keys_array = explode(':', $session_key); //checking if keys and value exist foreach ($session_keys_array as $key) { $counter++; $current_key .= '[\'' . $key . '\']'; if (!$_SESSION) { throw new Exception("\$_SESSION does not Exist"); } $prev_step = $_SESSION; if (array_key_exists($key, $prev_step) && count($session_keys_array) > $counter) { eval('$prevStep = $_SESSION' . $current_key . ';'); if (!is_array($prev_step) && count($session_keys_array) > $counter) { throw new Exception ("\$_SESSION$current_key is not an array"); } } else if ( is_array($prev_step) && eval('array_key_exists($_SESSION' . $current_key . ');') && count($session_keys_array) == $counter ) { eval('$result = $_SESSION' . $current_key . ';'); } else { throw new Exception("\$_SESSION$current_key does not Exist"); } } //checking if value is of right type if (!empty($is_object_of_type) && !$result instanceof $is_object_of_type) { throw new Exception("\$_SESSION$current_key is not instance of $is_object_of_type"); } //if we are here that means we have all safe data } catch(Exception $e) { //TODO:change Exception to SessionException and log this $result = null; } return $result; } $_SESSION = setSessionTestingData(); echo getKey($session_key);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Class "Agent" not found in /in/lBITW:4 Stack trace: #0 /in/lBITW(70): setSessionTestingData() #1 {main} thrown in /in/lBITW on line 4
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Class "Agent" not found in /in/lBITW:4 Stack trace: #0 /in/lBITW(70): setSessionTestingData() #1 {main} thrown in /in/lBITW on line 4
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught Error: Class 'Agent' not found in /in/lBITW:4 Stack trace: #0 /in/lBITW(70): setSessionTestingData() #1 {main} thrown in /in/lBITW on line 4
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Class 'Agent' not found in /in/lBITW on line 4
Process exited with code 255.

preferences:
258.81 ms | 402 KiB | 327 Q