3v4l.org

run code in 300+ PHP versions simultaneously
<?php function closure_to_str($func) { $refl = new \ReflectionFunction($func); // get reflection object $path = $refl->getFileName(); // absolute path of php file $begn = $refl->getStartLine(); // have to `-1` for array index $endn = $refl->getEndLine(); $dlim = PHP_EOL; $list = explode($dlim, file_get_contents($path)); // lines of php-file source $list = array_slice($list, ($begn-1), ($endn-($begn-1))); // lines of closure definition $last = (count($list)-1); // last line number if((substr_count($list[0],'function')>1)|| (substr_count($list[0],'{')>1) || (substr_count($list[$last],'}')>1)) { throw new \Exception("Too complex context definition in: `$path`. Check lines: $begn & $endn."); } $list[0] = ('function'.explode('function',$list[0])[1]); $list[$last] = (explode('}',$list[$last])[0].'}'); return implode($dlim,$list); } $test = 10; $dog2 = function($var=0) use ($test){ $var = 10; echo $var . PHP_EOL; return $test . $var; }; echo closure_to_str($dog2)."\n\n";

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.4.120.0080.01223.80
8.4.110.0060.00323.25
8.4.100.0090.01117.76
8.4.90.0100.01022.54
8.4.80.0050.00419.64
8.4.70.0060.00818.03
8.4.60.0080.00818.81
8.4.50.0060.00518.64
8.4.40.0030.00517.80
8.4.30.0030.00518.84
8.4.20.0060.00325.90
8.4.10.0140.00719.57
8.3.250.0120.00718.85
8.3.240.0120.00717.10
8.3.230.0120.00816.46
8.3.220.0110.00818.96
8.3.210.0090.00916.55
8.3.200.0110.00616.69
8.3.190.0090.01016.77
8.3.180.0140.00616.45
8.3.170.0090.00917.22
8.3.160.0170.00318.52
8.3.150.0060.01220.62
8.3.140.0060.01017.16
8.3.130.0040.00418.43
8.3.120.0060.00619.30
8.3.110.0040.00420.94
8.3.100.0060.00324.06
8.3.90.0050.00326.77
8.3.80.0090.00516.37
8.3.70.0070.01416.58
8.3.60.0220.00018.28
8.3.50.0120.00918.27
8.3.40.0140.00718.84
8.3.30.0150.00018.73
8.3.20.0060.00324.18
8.3.10.0070.00024.66
8.3.00.0000.00826.16
8.2.290.0140.00720.50
8.2.280.0080.01118.30
8.2.270.0070.01117.13
8.2.260.0060.00319.23
8.2.250.0070.00318.34
8.2.240.0050.00517.08
8.2.230.0060.00322.58
8.2.220.0080.00037.54
8.2.210.0040.00426.77
8.2.200.0070.00416.63
8.2.190.0070.00716.58
8.2.180.0110.00725.92
8.2.170.0140.00022.96
8.2.160.0000.01722.96
8.2.150.0040.00425.66
8.2.140.0070.00024.66
8.2.130.0000.00826.16
8.2.120.0000.00820.02
8.2.110.0160.00620.99
8.2.100.0090.00317.91
8.2.90.0050.00318.16
8.2.80.0070.00418.16
8.2.70.0030.00617.50
8.2.60.0080.00018.05
8.2.50.0040.00418.07
8.2.40.0050.00319.81
8.2.30.0070.00018.05
8.2.20.0000.00719.36
8.2.10.0040.00417.89
8.2.00.0000.00719.24
8.1.330.0110.00822.03
8.1.320.0050.00316.23
8.1.310.0100.00718.19
8.1.300.0040.01217.94
8.1.290.0060.00318.88
8.1.280.0120.00925.92
8.1.270.0080.00023.99
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0100.01322.60
8.1.230.0040.00722.75
8.1.220.0000.00817.76
8.1.210.0030.00518.77
8.1.200.0040.00417.35
8.1.190.0030.00517.23
8.1.180.0040.00418.10
8.1.170.0040.00418.59
8.1.160.0040.00419.04
8.1.150.0000.00718.64
8.1.140.0000.00817.39
8.1.130.0040.00417.49
8.1.120.0030.00617.50
8.1.110.0050.00317.44
8.1.100.0050.00317.39
8.1.90.0000.00817.48
8.1.80.0030.00717.39
8.1.70.0070.00017.36
8.1.60.0000.00717.69
8.1.50.0040.00417.57
8.1.40.0040.00417.45
8.1.30.0040.00417.62
8.1.20.0000.00717.70
8.1.10.0050.00317.58
8.1.00.0090.00617.46
8.0.300.0050.00220.07
8.0.290.0000.00816.75
8.0.280.0050.00318.59
8.0.270.0000.00818.11
8.0.260.0040.00416.93
8.0.250.0050.00316.96
8.0.240.0050.00316.95
8.0.230.0050.00217.02
8.0.220.0070.00416.91
8.0.210.0000.00817.05
8.0.200.0070.00016.94
8.0.190.0040.00417.06
8.0.180.0000.00716.90
8.0.170.0080.00016.98
8.0.160.0040.00417.06
8.0.150.0030.00617.02
8.0.140.0050.00216.94
8.0.130.0000.00513.41
8.0.120.0030.00613.31
8.0.110.0140.00013.34
8.0.100.0110.00213.29
8.0.90.0090.00513.37
8.0.80.0150.00013.36
8.0.70.0120.00313.36
8.0.60.0120.00413.33
8.0.50.0100.00013.38
8.0.30.0080.00513.31
8.0.20.0130.00013.32
8.0.10.0100.00013.45
8.0.00.0000.00613.45
7.4.330.0020.00314.81
7.4.320.0000.00716.68
7.4.300.0070.00116.61
7.4.290.0050.00316.40
7.4.280.0080.00016.53
7.4.270.0050.00616.51
7.4.260.0030.00313.39
7.4.250.0050.00213.33
7.4.240.0050.00513.42
7.4.230.0050.00513.34
7.4.220.0030.00613.23
7.4.210.0040.00413.28
7.4.200.0060.00013.41
7.4.190.0060.00013.32
7.4.180.0070.00013.36
7.4.160.0040.00413.41
7.4.150.0030.00313.41
7.4.140.0040.00413.24
7.4.130.0040.00813.30
7.4.120.0030.00613.20
7.4.110.0110.00013.20
7.4.100.0100.00313.32
7.4.90.0080.00513.22
7.4.80.0140.00013.33
7.4.70.0100.00313.21
7.4.60.0090.00413.30
7.4.50.0100.00313.12
7.4.40.0130.00013.14
7.4.30.0100.00213.22
7.4.20.0040.00813.24
7.4.10.0060.00613.27
7.4.00.0080.00313.26
7.3.330.0000.00716.50
7.3.320.0060.00613.48
7.3.310.0100.00413.38
7.3.300.0080.00413.21
7.3.290.0030.01013.53
7.3.280.0090.00313.28
7.3.270.0080.00213.44
7.3.260.0040.00513.21
7.3.250.0090.00313.23
7.3.240.0100.00313.40
7.3.230.0080.00313.24
7.3.220.0100.00013.31
7.3.210.0070.00413.34
7.3.200.0100.00013.29
7.3.190.0090.00313.12
7.3.180.0070.00713.16
7.3.170.0060.00515.25
7.3.160.0070.00313.18
7.3.150.0100.00413.32
7.3.140.0100.00413.20
7.3.130.0090.00613.32
7.3.120.0130.00013.31
7.3.110.0060.00813.25
7.3.100.0110.00313.11
7.3.90.0060.00613.21
7.3.80.0110.00213.16
7.3.70.0030.00913.31
7.3.60.0080.00513.27
7.3.50.0120.00313.42
7.3.40.0110.00313.38
7.3.30.0100.00313.36
7.3.20.0140.00015.39
7.3.10.0140.00015.22
7.3.00.0100.00515.06

preferences:
118.77 ms | 403 KiB | 5 Q