3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getKey($session_key, $is_object_of_type = null) { $current_key = ''; $counter = 0; try { $session_keys_array = explode(':', $session_key); if (!$_SESSION) { throw new Exception("\$_SESSION does not Exist"); } $prev_step = $_SESSION; //checking if keys and value exist foreach ($session_keys_array as $key) { $counter++; $current_key .= '[\'' . $key . '\']'; echo 0; if (array_key_exists($key, $prev_step) && count($session_keys_array) > $counter) { echo 1; $prevStep = $prev_step[$key]; var_dump($prevStep); if (!is_array($prev_step) && count($session_keys_array) > $counter) { echo 2; throw new Exception ("\$_SESSION$current_key is not an array"); } } else if ( is_array($prev_step) && array_key_exists($key, $prev_step) && count($session_keys_array) == $counter ) { echo 3; $result = $prev_step[$key]; } else { echo 4; throw new Exception("\$_SESSION$current_key does not Exist"); } } echo 5; //checking if value is of right type if (!empty($is_object_of_type) && !$result instanceof $is_object_of_type) { echo 6; throw new Exception("\$_SESSION$current_key is not instance of $is_object_of_type"); } echo 7; //if we are here that means we have all safe data } catch(Exception $e) { //TODO:change Exception to SessionException and log this echo 8; $result = null; } echo 9; return $result; } function setSessionTestingData() { $agent = 5; $ticket = 6; $_SESSION = array( 'agent_id' => '2', 'ticket_id' => '3', 'agent' => $agent, 'ticket' => $ticket, 'sub_array' => array( 'sub' => 4, 'agent' => $agent, 'ticket' => $ticket, ), ); return $_SESSION; } $_SESSION = setSessionTestingData(); echo getKey('sub_array:sub');

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0170.00716.63
8.3.50.0060.01121.11
8.3.40.0040.01118.85
8.3.30.0070.00718.84
8.3.20.0040.00420.18
8.3.10.0040.00421.68
8.3.00.0080.00023.51
8.2.180.0070.00716.63
8.2.170.0100.00722.96
8.2.160.0070.00720.36
8.2.150.0050.00324.18
8.2.140.0030.00524.66
8.2.130.0040.00421.12
8.2.120.0040.00426.35
8.2.110.0040.00420.92
8.2.100.0040.00817.97
8.2.90.0080.00018.15
8.2.80.0040.00418.19
8.2.70.0040.00417.75
8.2.60.0030.00618.05
8.2.50.0030.00618.09
8.2.40.0000.00922.18
8.2.30.0070.00019.59
8.2.20.0070.00017.90
8.2.10.0000.00718.15
8.2.00.0040.00418.16
8.1.280.0140.00725.92
8.1.270.0080.00022.14
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0100.00022.47
8.1.230.0060.00620.96
8.1.220.0000.00917.74
8.1.210.0080.00018.85
8.1.200.0030.00617.25
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0060.00318.50
8.1.160.0000.00720.79
8.1.150.0060.00318.88
8.1.140.0030.00519.60
8.1.130.0030.00317.67
8.1.120.0040.00417.38
8.1.110.0040.00417.48
8.1.100.0000.00717.50
8.1.90.0060.00317.53
8.1.80.0030.00617.41
8.1.70.0050.00217.53
8.1.60.0070.00017.65
8.1.50.0090.00017.57
8.1.40.0030.00617.54
8.1.30.0030.00617.58
8.1.20.0060.00317.59
8.1.10.0030.00617.65
8.1.00.0000.00817.45
8.0.300.0000.00719.81
8.0.290.0070.00016.75
8.0.280.0000.00818.54
8.0.270.0030.00317.25
8.0.260.0000.00717.20
8.0.250.0030.00317.07
8.0.240.0000.00816.95
8.0.230.0000.00717.02
8.0.220.0040.00416.98
8.0.210.0040.00417.00
8.0.200.0050.00217.05
8.0.190.0000.00817.05
8.0.180.0000.00816.90
8.0.170.0000.00816.89
8.0.160.0030.00316.97
8.0.150.0050.00316.96
8.0.140.0040.00316.95
8.0.130.0050.00013.34
8.0.120.0040.00416.86
8.0.110.0080.00017.01
8.0.100.0070.00016.83
8.0.90.0040.00417.04
8.0.80.0160.00016.98
8.0.70.0030.00517.04
8.0.60.0040.00416.81
8.0.50.0000.00716.88
8.0.30.0140.00617.16
8.0.20.0130.00717.40
8.0.10.0070.00017.14
8.0.00.0110.00716.99
7.4.330.0000.00516.69
7.4.320.0000.00616.62
7.4.300.0030.00316.63
7.4.290.0070.00016.61
7.4.280.0000.00816.44
7.4.270.0030.00316.61
7.4.260.0030.00516.63
7.4.250.0040.00416.49
7.4.240.0000.00716.63
7.4.230.0000.00716.52
7.4.220.0190.00016.57
7.4.210.0040.01116.56
7.4.200.0020.00516.53
7.4.160.0030.01316.60
7.4.150.0100.00717.40
7.4.140.0150.00917.86
7.4.130.0050.01216.54
7.4.120.0130.00416.67
7.4.110.0110.00716.50
7.4.100.0110.00716.62
7.4.90.0060.01216.55
7.4.80.0030.01519.39
7.4.70.0090.00916.49
7.4.60.0190.00316.68
7.4.50.0040.01216.48
7.4.40.0060.01116.43
7.4.30.0090.00916.77
7.4.00.0070.00715.14
7.3.330.0050.00013.23
7.3.320.0000.00513.27
7.3.310.0000.00716.47
7.3.300.0000.00716.32
7.3.290.0000.00816.32
7.3.280.0050.01316.44
7.3.270.0100.01017.40
7.3.260.0110.01116.63
7.3.250.0090.00916.49
7.3.240.0080.01016.64
7.3.230.0080.00816.39
7.3.210.0070.01016.44
7.3.200.0130.01019.39
7.3.190.0080.00816.56
7.3.180.0070.01016.57
7.3.170.0080.00816.52
7.3.160.0060.00916.50
7.3.10.0030.01316.43
7.3.00.0000.00816.71
7.2.330.0130.00516.79
7.2.320.0100.00716.70
7.2.310.0070.01016.63
7.2.300.0100.01316.70
7.2.290.0050.01116.76
7.2.130.0140.00017.03
7.2.120.0060.00616.90
7.2.110.0000.01516.92
7.2.100.0000.01116.69
7.2.90.0030.00917.05
7.2.80.0060.00616.99
7.2.70.0000.00917.07
7.2.60.0080.00817.11
7.2.50.0040.01116.90
7.2.40.0050.00517.09
7.2.30.0110.00416.78
7.2.20.0080.00516.71
7.2.10.0080.00416.97
7.2.00.0060.00718.22
7.1.250.0120.00315.72
7.1.100.0040.01218.16
7.1.70.0040.00717.25
7.1.60.0060.01919.40
7.1.50.0090.01216.98
7.1.00.0030.07322.40
7.0.200.0410.00314.73
7.0.60.0200.07721.82
7.0.50.0070.06017.74
7.0.40.0130.07720.15
7.0.30.0370.07720.34
7.0.20.0100.05320.10
7.0.10.0130.06020.06
7.0.00.0130.06720.25
5.6.280.0000.03320.94
5.6.210.0070.08320.66
5.6.200.0170.07018.16
5.6.190.0170.03720.66
5.6.180.0300.03720.61
5.6.170.0230.03720.56
5.6.160.0030.08720.54
5.6.150.0070.07018.19
5.6.140.0170.06318.16
5.6.130.0070.06718.23
5.6.120.0070.08020.91
5.6.110.0170.07321.00
5.6.100.0100.06721.01
5.6.90.0130.08021.04
5.6.80.0130.07020.30
5.5.350.0330.07020.48
5.5.340.0130.07017.97
5.5.330.0070.06320.43
5.5.320.0130.05720.27
5.5.310.0330.07320.20
5.5.300.0070.07717.99
5.5.290.0100.03718.08
5.5.280.0230.06720.67
5.5.270.0130.07320.77
5.5.260.0130.07320.89
5.5.250.0130.07320.70
5.5.240.0030.06020.25

preferences:
71.19 ms | 401 KiB | 5 Q