3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo "Should pass" . PHP_EOL; var_dump(to_int("0")); var_dump(to_int(0)); var_dump(to_int(0.0)); var_dump(to_int("0.0")); var_dump(to_int("10")); var_dump(to_int(10)); var_dump(to_int(10.0)); var_dump(to_int("10.0")); echo "Should fail" . PHP_EOL; var_dump(to_int(1.5)); var_dump(to_int("1.5")); var_dump(to_int("75e-5")); var_dump(to_int("31e+7")); var_dump(to_int("10abc")); var_dump(to_int("abc10")); var_dump(to_int(INF)); var_dump(to_int(-INF)); var_dump(to_int(NAN)); var_dump(to_int(PHP_INT_MAX * 2)); var_dump(to_int(null)); var_dump(to_int(true)); var_dump(to_int(false)); var_dump(to_int(new stdClass())); var_dump(to_int(fopen("data:text/html,foobar", "r"))); var_dump(to_int([])); /** * Returns the value as an int, or false if it cannot be safely cast * @param mixed $val * @return int */ function to_int($val) { switch (gettype($val)) { case "integer": return $val; case "double": if ($val === (float) (int) $val) { return (int) $val; } else { return false; } case "string": $val = trim($val, " \t\n\r\v\f"); // trim whitespace $float = filter_var($val, FILTER_VALIDATE_FLOAT); return ($float !== false && (int) $val == $float) ? (int) $val : false; default: return false; } }

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.0070.00718.43
8.3.50.0200.00922.00
8.3.40.0110.00418.97
8.3.30.0110.00319.13
8.3.20.0070.00020.41
8.3.10.0050.00320.61
8.3.00.0040.00417.50
8.2.180.0110.00425.92
8.2.170.0070.00719.09
8.2.160.0100.00722.96
8.2.150.0000.00825.66
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00422.29
8.2.110.0030.00722.44
8.2.100.0060.00617.91
8.2.90.0040.00419.22
8.2.80.0080.00017.97
8.2.70.0080.00017.75
8.2.60.0000.00917.93
8.2.50.0060.00318.07
8.2.40.0000.00918.34
8.2.30.0040.00419.33
8.2.20.0000.00817.78
8.2.10.0060.00318.27
8.2.00.0000.00717.87
8.1.280.0100.01025.92
8.1.270.0030.00523.85
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0040.00423.81
8.1.230.0070.00419.25
8.1.220.0000.00817.91
8.1.210.0040.00418.77
8.1.200.0000.00917.35
8.1.190.0000.00817.47
8.1.180.0040.00418.10
8.1.170.0000.00918.84
8.1.160.0030.00622.29
8.1.150.0040.00418.95
8.1.140.0020.00517.68
8.1.130.0050.00520.30
8.1.120.0070.00317.68
8.1.110.0040.00417.66
8.1.100.0050.00217.64
8.1.90.0070.00017.59
8.1.80.0030.00517.49
8.1.70.0070.00017.51
8.1.60.0030.00717.80
8.1.50.0060.00317.71
8.1.40.0000.00817.65
8.1.30.0080.00017.79
8.1.20.0020.00517.71
8.1.10.0040.00417.59
8.1.00.0000.00817.68
8.0.300.0070.00018.77
8.0.290.0050.00216.75
8.0.280.0000.00718.71
8.0.270.0050.00517.53
8.0.260.0060.00320.22
8.0.250.0030.00317.20
8.0.240.0030.00317.23
8.0.230.0070.00017.20
8.0.220.0070.00016.99
8.0.210.0040.00416.99
8.0.200.0040.00417.21
8.0.190.0040.00417.27
8.0.180.0000.00817.04
8.0.170.0040.00417.04
8.0.160.0000.00816.99
8.0.150.0020.00517.02
8.0.140.0000.00817.08
8.0.130.0000.00513.62
8.0.120.0080.00016.96
8.0.110.0040.00417.08
8.0.100.0000.00716.99
8.0.90.0040.00417.14
8.0.80.0070.01217.13
8.0.70.0070.01617.18
8.0.60.0120.00816.97
8.0.50.0090.01316.99
8.0.30.0080.01417.34
8.0.20.0110.00817.34
8.0.10.0130.00917.20
8.0.00.0120.00717.08
7.4.330.0020.00215.21
7.4.320.0000.00616.77
7.4.300.0030.00316.82
7.4.290.0050.00216.69
7.4.280.0000.00716.76
7.4.270.0070.00016.77
7.4.260.0030.00316.70
7.4.250.0080.00016.66
7.4.240.0030.00516.73
7.4.230.0030.00316.82
7.4.220.0170.00616.68
7.4.210.0040.01416.82
7.4.200.0070.01316.86
7.4.190.0100.01016.92
7.4.180.0090.00916.72
7.4.160.0080.00816.74
7.4.150.0130.01117.07
7.4.140.0080.01217.45
7.4.130.0070.01216.66
7.4.120.0120.00916.75
7.4.110.0080.01016.67
7.4.100.0120.00716.79
7.4.90.0080.01416.79
7.4.80.0100.00817.87
7.4.70.0050.01216.72
7.4.60.0130.00516.82
7.4.50.0080.00616.57
7.4.40.0090.01016.58
7.4.30.0110.00816.65
7.4.20.0150.00416.50
7.4.10.0090.01116.54
7.4.00.0080.00815.59
7.3.330.0060.00013.61
7.3.320.0000.00513.57
7.3.310.0070.00016.68
7.3.300.0030.00316.64
7.3.290.0060.00916.57
7.3.280.0110.00716.63
7.3.270.0090.01216.99
7.3.260.0090.00816.58
7.3.250.0130.00416.62
7.3.240.0110.00916.52
7.3.230.0090.00816.58
7.3.220.0060.01216.45
7.3.210.0130.00316.55
7.3.200.0100.00817.95
7.3.190.0070.00916.43
7.3.180.0090.00616.52
7.3.170.0060.01116.50
7.3.160.0070.00916.47
7.3.150.0100.00616.51
7.3.140.0120.00616.50
7.3.130.0060.00916.45
7.3.120.0080.01015.39
7.3.110.0100.00615.56
7.3.100.0090.00715.57
7.3.90.0060.00915.59
7.3.80.0040.01315.63
7.3.70.0060.01015.45
7.3.60.0030.01215.48
7.3.50.0110.00515.56
7.3.40.0040.00915.58
7.3.30.0070.00815.52
7.3.20.0090.00616.80
7.3.10.0090.00616.80
7.3.00.0090.00816.74
7.2.340.0170.01316.65
7.2.330.0150.00816.68
7.2.320.0070.01416.65
7.2.310.0080.01316.81
7.2.300.0120.01116.87
7.2.290.0340.00616.66
7.2.280.0180.00916.70
7.2.270.0130.01316.61
7.2.260.0230.00416.59
7.2.250.0100.00715.77
7.2.240.0150.00615.78
7.2.230.0120.00815.58
7.2.220.0100.00915.76
7.2.210.0110.01115.69
7.2.200.0140.00515.70
7.2.190.0100.01115.68
7.2.180.0140.00815.76
7.2.170.0170.00615.67
7.2.160.0100.01415.90
7.2.150.0110.00816.95
7.2.140.0110.01217.04
7.2.130.0140.01116.99
7.2.120.0170.00517.03
7.2.110.0110.01316.88
7.2.100.0080.01216.99
7.2.90.0120.00816.94
7.2.80.0260.00716.84
7.2.70.0160.00916.86
7.2.60.0120.00816.75
7.2.50.0100.01017.06
7.2.40.0720.00716.95
7.2.30.0090.01316.96
7.2.20.0140.00917.00
7.2.10.0150.00316.99
7.2.00.0090.01017.84
7.1.330.0140.00615.80
7.1.320.0070.01115.75
7.1.310.0100.01216.01
7.1.300.0110.00915.87
7.1.290.0070.01215.85
7.1.280.0090.00915.81
7.1.270.0110.00715.93
7.1.260.0090.00815.90
7.1.250.0150.00815.85
7.1.240.0120.01115.76
7.1.230.0140.00515.92
7.1.220.0110.01215.74
7.1.210.0060.01515.93
7.1.200.0090.01115.95
7.1.190.0100.01115.84
7.1.180.0130.00915.95
7.1.170.0120.00815.76
7.1.160.0410.00815.78
7.1.150.0130.00915.74
7.1.140.0110.01315.76
7.1.130.0170.00315.82
7.1.120.0100.01115.85
7.1.110.0140.00815.88
7.1.100.0120.00616.73
7.1.90.0200.00315.72
7.1.80.0110.00815.82
7.1.70.0090.00616.13
7.1.60.0140.01017.03
7.1.50.0100.01016.24
7.1.40.0170.00515.92
7.1.30.0130.00715.75
7.1.20.0140.00815.89
7.1.10.0100.00915.88
7.1.00.0090.02718.03
7.0.330.0070.01115.56
7.0.320.0080.01615.59
7.0.310.0130.00915.59
7.0.300.0150.00315.44
7.0.290.0120.00615.42
7.0.280.0470.00515.35
7.0.270.0110.00915.49
7.0.260.0110.00615.47
7.0.250.0140.01015.57
7.0.240.0080.01115.39
7.0.230.0100.00915.51
7.0.220.0090.00815.36
7.0.210.0110.00815.48
7.0.200.0090.00615.94
7.0.190.0080.01115.38
7.0.180.0150.00715.41
7.0.170.0130.00515.60
7.0.160.0120.00715.59
7.0.150.0120.00615.53
7.0.140.0090.03017.63
7.0.130.0140.00715.48
7.0.120.0110.00915.58
7.0.110.0100.00715.40
7.0.100.0130.00615.52
7.0.90.0090.01015.47
7.0.80.0260.00315.44
7.0.70.0350.00815.43
7.0.60.0120.03216.98
7.0.50.0080.01816.26
7.0.40.0120.01716.47
7.0.30.0160.02216.43
7.0.20.0190.02916.34
7.0.10.0060.02216.40
7.0.00.0110.03216.34
5.6.400.0130.00915.22
5.6.390.0110.00515.25
5.6.380.0130.01115.22
5.6.370.0110.00915.40
5.6.360.0080.01015.23
5.6.350.0040.01615.33
5.6.340.0110.01115.16
5.6.330.0080.01015.30
5.6.320.0100.00815.31
5.6.310.0070.01015.04
5.6.300.0090.01215.16
5.6.290.0090.01315.21
5.6.280.0100.03017.21
5.6.270.0140.00615.38
5.6.260.0090.01115.33
5.6.250.0110.00715.20
5.6.240.0140.00615.24
5.6.230.0120.00615.43
5.6.220.0220.01015.27
5.6.210.0120.02517.11
5.6.200.0120.03216.25
5.6.190.0110.02417.16
5.6.180.0210.02516.94
5.6.170.0150.03117.09
5.6.160.0090.02817.06
5.6.150.0110.03116.41
5.6.140.0070.03216.36
5.6.130.0120.02616.33
5.6.120.0110.03217.23
5.6.110.0070.03617.17
5.6.100.0090.03317.18
5.6.90.0130.02517.25
5.6.80.0240.02216.99
5.6.70.0120.00615.29
5.6.60.0110.00815.37
5.6.50.0080.01015.33
5.6.40.0100.01015.22
5.6.30.0140.00515.21
5.6.20.0120.00515.32
5.6.10.0120.00615.19
5.6.00.0130.00715.19
5.5.380.0160.00615.23
5.5.370.0110.00715.30
5.5.360.0130.00515.04
5.5.350.0130.03416.99
5.5.340.0120.02116.28
5.5.330.0080.02117.00
5.5.320.0100.03416.99
5.5.310.0140.01916.91
5.5.300.0110.02916.28
5.5.290.0090.03516.22
5.5.280.0100.01717.15
5.5.270.0050.03317.06
5.5.260.0100.02117.14
5.5.250.0170.03117.01
5.5.240.0130.03116.89
5.5.230.0080.01015.19
5.5.220.0110.00715.17
5.5.210.0090.00815.26
5.5.200.0120.00815.05
5.5.190.0080.01415.24
5.5.180.0140.00715.25
5.5.170.0080.01315.19
5.5.160.0060.01115.20
5.5.150.0130.00715.05
5.5.140.0110.01115.10
5.5.130.0110.00615.04
5.5.120.0140.00615.08
5.5.110.0090.01015.12
5.5.100.0090.00915.12
5.5.90.0070.01015.12
5.5.80.0100.00715.11
5.5.70.0070.01415.14
5.5.60.0150.00315.04
5.5.50.0110.01015.14
5.5.40.0110.00615.03
5.5.30.0130.00515.17
5.5.20.0110.00815.35
5.5.10.0100.01015.11
5.5.00.0150.00115.18
5.4.450.0090.01714.68
5.4.440.0420.02214.73
5.4.430.0320.02414.74
5.4.420.0290.00314.65
5.4.410.0300.00614.67
5.4.400.0270.00614.58
5.4.390.0280.00414.53
5.4.380.0220.02414.39
5.4.370.0160.02814.42
5.4.360.0170.02414.33
5.4.350.0190.02214.38
5.4.340.0220.02214.37
5.4.330.0100.00412.26
5.4.320.0090.01512.36
5.4.310.0110.01812.36
5.4.300.0070.01712.34
5.4.290.0090.01712.36
5.4.280.0100.01512.30
5.4.270.0090.01712.31
5.4.260.0090.01812.30
5.4.250.0080.02012.28
5.4.240.0070.01812.29
5.4.230.0060.02112.24
5.4.220.0090.01412.22
5.4.210.0080.01712.23
5.4.200.0050.02212.21
5.4.190.0080.02112.22
5.4.180.0070.01812.22
5.4.170.0060.01912.24
5.4.160.0100.01912.23
5.4.150.0110.01612.24
5.4.140.0050.02212.22
5.4.130.0110.01312.24
5.4.120.0120.01512.19
5.4.110.0090.02112.21
5.4.100.0120.01512.23
5.4.90.0060.01812.19
5.4.80.0090.01812.23
5.4.70.0080.01812.23
5.4.60.0090.01712.23
5.4.50.0110.01512.19
5.4.40.0090.01812.20
5.4.30.0060.01912.21
5.4.20.0100.01512.22
5.4.10.0060.01812.21
5.4.00.0070.01711.95

preferences:
45.42 ms | 401 KiB | 5 Q