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 = "\n"; // or 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($list,$dlim); } $dog = ['bark'=>function(){}]; $dog2 = ['bark'=>function($foo = '{'){}]; echo closure_to_str($dog['bark'])."\n\n"; echo closure_to_str($dog2['bark'])."\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.5.30.0090.00819.64
8.5.20.0100.00818.75
8.5.10.0130.00816.86
8.5.00.0140.00920.29
8.4.180.0140.00819.63
8.4.170.0110.00923.81
8.4.160.0130.01023.94
8.4.150.0070.00616.95
8.4.140.0120.01017.64
8.4.130.0140.00718.00
8.4.120.0150.00624.01
8.4.110.0130.00919.01
8.4.100.0040.00417.73
8.4.90.0090.01120.39
8.4.80.0130.00519.03
8.4.70.0110.00518.70
8.4.60.0060.00318.82
8.4.50.0060.01419.38
8.4.40.0100.01019.75
8.4.30.0070.00417.69
8.4.20.0120.00817.79
8.4.10.0130.00319.78
8.3.300.0080.01222.64
8.3.290.0120.00920.88
8.3.280.0110.01118.70
8.3.270.0130.00616.81
8.3.260.0120.00816.61
8.3.250.0140.00617.20
8.3.240.0130.00717.24
8.3.230.0080.01016.83
8.3.220.0160.00418.87
8.3.210.0050.00316.63
8.3.200.0050.00616.80
8.3.190.0130.00618.77
8.3.180.0040.00516.63
8.3.170.0030.00717.03
8.3.160.0070.01116.90
8.3.150.0070.00319.10
8.3.140.0030.00716.98
8.3.130.0080.00018.59
8.3.120.0060.01318.92
8.3.110.0040.00420.94
8.3.100.0030.00616.80
8.3.90.0120.00626.77
8.3.80.0060.00318.43
8.3.70.0140.00716.49
8.3.60.0060.01218.55
8.3.50.0100.01017.54
8.3.40.0090.00619.03
8.3.30.0110.00419.02
8.3.20.0040.00420.21
8.3.10.0080.00020.91
8.3.00.0080.00021.02
8.2.300.0120.00918.75
8.2.290.0090.00916.51
8.2.280.0130.00518.86
8.2.270.0030.01417.17
8.2.260.0110.00418.81
8.2.250.0090.00018.59
8.2.240.0030.00619.30
8.2.230.0030.00722.58
8.2.220.0040.00424.06
8.2.210.0040.00426.77
8.2.200.0000.00616.75
8.2.190.0120.00316.75
8.2.180.0150.00318.38
8.2.170.0080.00622.96
8.2.160.0110.00319.41
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00819.76
8.2.110.0040.00722.27
8.2.100.0090.00317.84
8.2.90.0000.00819.20
8.2.80.0040.00418.04
8.2.70.0080.00017.75
8.2.60.0040.00418.04
8.2.50.0080.00018.10
8.2.40.0040.00422.20
8.2.30.0050.00319.28
8.2.20.0000.00718.05
8.2.10.0000.00718.16
8.2.00.0000.00718.22
8.1.340.0100.00921.63
8.1.330.0110.00916.44
8.1.320.0150.00516.51
8.1.310.0080.00016.73
8.1.300.0030.00916.38
8.1.290.0080.00330.84
8.1.280.0140.00725.92
8.1.270.0040.00422.14
8.1.260.0030.00526.35
8.1.250.0000.00728.09
8.1.240.0050.00518.98
8.1.230.0040.00819.15
8.1.220.0000.00817.74
8.1.210.0090.00018.77
8.1.200.0030.00617.25
8.1.190.0060.00617.23
8.1.180.0000.00818.10
8.1.170.0040.00418.65
8.1.160.0040.00419.06
8.1.150.0000.00718.85
8.1.140.0000.00719.53
8.1.130.0050.00318.84
8.1.120.0040.00417.50
8.1.110.0060.00317.38
8.1.100.0060.00317.50
8.1.90.0050.00217.45
8.1.80.0000.00717.37
8.1.70.0030.00617.50
8.1.60.0080.00017.65
8.1.50.0050.00317.49
8.1.40.0050.00517.41
8.1.30.0030.00617.74
8.1.20.0040.00417.69
8.1.10.0050.00317.48
8.1.00.0040.00417.56
8.0.300.0050.00318.77
8.0.290.0080.00016.75
8.0.280.0030.00318.56
8.0.270.0000.00816.86
8.0.260.0000.00619.06
8.0.250.0030.00517.11
8.0.240.0000.00717.16
8.0.230.0040.00417.02
8.0.220.0040.00417.07
8.0.210.0000.00717.06
8.0.200.0030.00317.13
8.0.190.0080.00017.09
8.0.180.0030.00516.96
8.0.170.0070.00017.09
8.0.160.0000.00817.06
8.0.150.0050.00216.97
8.0.140.0040.00417.02
8.0.130.0000.00613.52
8.0.120.0060.00316.93
8.0.110.0040.00416.84
8.0.100.0030.00616.88
8.0.90.0040.00417.05
8.0.80.0130.00617.00
8.0.70.0030.00517.02
8.0.60.0000.00717.06
8.0.50.0040.00417.00
8.0.30.0110.00617.26
8.0.20.0110.01117.40
8.0.10.0040.00416.96
8.0.00.0120.00617.16
7.4.330.0030.00215.55
7.4.320.0040.00416.55
7.4.300.0060.00316.56
7.4.290.0070.00316.54
7.4.280.0030.00516.50
7.4.270.0030.00316.70
7.4.260.0000.00816.48
7.4.250.0000.00816.51
7.4.240.0040.00416.66
7.4.230.0050.00316.71
7.4.220.0130.00516.53
7.4.210.0060.00916.43
7.4.200.0030.00316.52
7.4.160.0110.00616.65
7.4.150.0060.01317.40
7.4.140.0080.00917.86
7.4.130.0110.01016.58
7.4.120.0080.01116.58
7.4.110.0130.01016.78
7.4.100.0030.01816.54
7.4.90.0060.01716.48
7.4.80.0120.00919.39
7.4.70.0100.00616.60
7.4.60.0030.01416.86
7.4.50.0100.00616.64
7.4.40.0130.01016.55
7.4.30.0110.00916.75
7.4.00.0070.01015.07
7.3.330.0030.00313.39
7.3.320.0000.00513.39
7.3.310.0070.00016.58
7.3.300.0070.00016.59
7.3.290.0060.00916.50
7.3.280.0100.00916.53
7.3.270.0060.02117.40
7.3.260.0100.01316.62
7.3.250.0120.00616.57
7.3.240.0120.00716.59
7.3.230.0090.00916.42
7.3.210.0070.01116.54
7.3.200.0040.01416.63
7.3.190.0080.00816.58
7.3.180.0030.01416.69
7.3.170.0000.02016.52
7.3.160.0120.00416.50
7.2.330.0080.01116.79
7.2.320.0110.00816.56
7.2.310.0060.01216.90
7.2.300.0090.00916.58
7.2.290.0090.00916.71
7.2.80.0070.00716.66
7.2.60.0060.00617.09
7.1.200.0030.01315.69
7.1.70.1740.01615.58
7.1.60.2050.02333.29
7.1.50.2530.01632.79
7.1.40.2270.02032.65
7.1.30.2620.02332.69
7.1.20.2410.01232.69
7.1.10.1510.01014.84
7.1.00.1810.01014.84
7.0.200.2020.01014.96
7.0.190.2430.00914.90
7.0.180.1720.00714.45
7.0.170.2600.01314.52
7.0.160.2260.01014.43
7.0.150.1940.01714.59
7.0.140.1680.01214.53
7.0.130.2110.01214.82
7.0.120.1540.01314.79
7.0.110.1920.00714.41
7.0.100.1930.01014.52
7.0.90.1860.00614.66
7.0.80.1800.01214.62
7.0.70.2300.01014.61
7.0.60.1920.01014.45
7.0.50.2320.00314.64
7.0.40.1950.00714.61
7.0.30.1790.00714.73
7.0.20.2460.01214.73
7.0.10.2320.01614.67
7.0.00.2560.00914.93

preferences:
48.69 ms | 1521 KiB | 5 Q