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")); var_dump(to_int("10.")); 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.0090.01218.68
8.3.50.0110.00922.06
8.3.40.0040.01118.60
8.3.30.0030.01419.21
8.3.20.0050.00320.46
8.3.10.0030.00620.52
8.3.00.0000.00817.50
8.2.180.0090.00616.75
8.2.170.0110.00322.96
8.2.160.0080.00620.51
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0080.00022.26
8.2.110.0030.00720.94
8.2.100.0000.01117.91
8.2.90.0040.00419.17
8.2.80.0080.00017.97
8.2.70.0060.00317.63
8.2.60.0050.00318.16
8.2.50.0040.00418.10
8.2.40.0050.00518.20
8.2.30.0000.00819.41
8.2.20.0000.00817.84
8.2.10.0000.00818.11
8.2.00.0080.00017.73
8.1.280.0070.00725.92
8.1.270.0050.00323.91
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0030.00624.04
8.1.230.0040.00817.95
8.1.220.0040.00417.91
8.1.210.0000.00818.77
8.1.200.0000.00917.60
8.1.190.0030.00617.47
8.1.180.0000.00818.10
8.1.170.0040.00418.79
8.1.160.0000.00722.23
8.1.150.0070.00018.98
8.1.140.0080.00017.51
8.1.130.0060.00320.45
8.1.120.0000.00717.58
8.1.110.0080.00017.62
8.1.100.0040.00417.52
8.1.90.0070.00017.66
8.1.80.0020.00517.53
8.1.70.0030.00317.50
8.1.60.0030.00617.63
8.1.50.0040.00417.59
8.1.40.0060.00317.56
8.1.30.0000.00817.69
8.1.20.0030.00617.85
8.1.10.0000.00717.66
8.1.00.0020.00517.55
8.0.300.0000.00818.77
8.0.290.0000.00817.00
8.0.280.0050.00318.56
8.0.270.0080.00017.48
8.0.260.0000.00718.70
8.0.250.0040.00417.08
8.0.240.0070.00017.16
8.0.230.0070.00017.06
8.0.220.0070.00017.12
8.0.210.0050.00217.11
8.0.200.0080.00017.18
8.0.190.0040.00417.16
8.0.180.0050.00217.23
8.0.170.0030.00617.01
8.0.160.0000.00817.16
8.0.150.0040.00417.09
8.0.140.0040.00417.01
8.0.130.0030.00313.57
8.0.120.0000.00816.98
8.0.110.0000.00717.15
8.0.100.0000.00717.12
8.0.90.0000.00717.17
8.0.80.0070.01417.13
8.0.70.0050.00317.10
8.0.60.0020.00516.98
8.0.50.0000.00717.12
8.0.30.0220.00517.25
8.0.20.0100.01117.41
8.0.10.0050.00217.05
8.0.00.0070.01117.03
7.4.330.0000.00515.20
7.4.320.0060.00016.57
7.4.300.0030.00316.61
7.4.290.0030.00316.66
7.4.280.0050.00316.75
7.4.270.0040.00416.77
7.4.260.0030.00316.79
7.4.250.0060.00316.73
7.4.240.0040.00316.61
7.4.230.0030.00316.90
7.4.220.0070.01416.68
7.4.210.0030.01116.76
7.4.200.0030.00616.82
7.4.160.0030.01216.70
7.4.150.0090.01617.40
7.4.140.0130.00817.86
7.4.130.0070.01116.66
7.4.120.0160.00516.71
7.4.110.0110.00716.83
7.4.100.0180.00016.68
7.4.90.0100.01516.62
7.4.80.0060.01219.03
7.4.70.0110.00516.78
7.4.60.0090.00816.70
7.4.50.0060.00316.76
7.4.40.0060.01916.55
7.4.30.0120.00316.75
7.4.00.0050.01215.24
7.3.330.0060.00013.45
7.3.320.0030.00313.61
7.3.310.0000.00716.56
7.3.300.0040.00416.54
7.3.290.0000.01416.63
7.3.280.0040.01216.60
7.3.270.0070.01317.40
7.3.260.0000.01716.61
7.3.250.0090.00916.75
7.3.240.0140.00316.59
7.3.230.0110.00816.58
7.3.210.0030.01416.61
7.3.200.0060.01219.39
7.3.190.0140.00716.45
7.3.180.0070.01616.80
7.3.170.0070.01016.70
7.3.160.0030.01216.73
7.3.120.0070.01014.95
7.3.110.0100.00715.07
7.3.100.0030.00915.03
7.3.90.0030.00615.13
7.3.80.0030.01315.27
7.3.70.0060.00615.09
7.3.60.0000.01015.02
7.3.50.0060.00615.01
7.3.40.0030.00714.94
7.3.30.0080.00714.72
7.3.20.0100.00716.76
7.3.10.0110.00316.77
7.3.00.0030.00816.88
7.2.330.0120.00616.89
7.2.320.0150.00917.02
7.2.310.0060.01216.92
7.2.300.0000.01716.77
7.2.290.0090.00916.99
7.2.250.0040.01415.41
7.2.240.0100.01015.39
7.2.230.0040.01415.18
7.2.220.0060.00314.98
7.2.210.0000.01215.45
7.2.200.0070.00715.41
7.2.190.0070.00715.09
7.2.180.0030.00615.23
7.2.170.0080.00315.12
7.2.130.0060.00617.02
7.2.120.0030.01317.02
7.2.110.0070.00717.25
7.2.100.0000.01516.87
7.2.90.0080.00817.16
7.2.80.0040.01117.02
7.2.70.0070.01116.93
7.2.60.0110.00517.05
7.2.50.0120.00316.99
7.2.40.0030.01417.04
7.2.30.0110.00417.11
7.2.20.0080.00316.85
7.2.10.0060.00917.12
7.2.00.0070.00317.13
7.1.330.0040.00816.14
7.1.320.0030.01016.08
7.1.310.0030.00915.60
7.1.300.0060.00315.95
7.1.290.0030.01215.84
7.1.280.0070.01116.03
7.1.270.0030.01415.73
7.1.260.0070.01015.83
7.1.250.0030.00716.01
7.1.240.0030.00716.07
7.1.230.0100.00315.89
7.1.220.0030.00616.00
7.1.210.0030.01015.91
7.1.200.0070.00715.79
7.1.190.0060.00615.99
7.1.180.0030.01015.84
7.1.170.0110.00316.00
7.1.160.0070.00715.77
7.1.150.0070.00716.02
7.1.140.0070.00315.63
7.1.130.0060.00315.89
7.1.120.0030.00615.71
7.1.110.0100.00416.14
7.1.100.0050.00917.18
7.1.90.0000.01516.02
7.1.80.0070.00716.05
7.1.70.0070.00416.45
7.1.60.0090.00817.55
7.1.50.0060.00616.49
7.1.40.0030.00615.94
7.1.30.0040.01015.96
7.1.20.0060.00315.90
7.1.10.0060.00315.93
7.1.00.0030.04419.27
7.0.330.0090.00315.53
7.0.320.0040.01115.57
7.0.310.0000.01315.48
7.0.300.0030.01015.38
7.0.290.0100.00715.52
7.0.280.0050.00515.11
7.0.270.0130.00315.50
7.0.260.0060.01015.66
7.0.250.0060.00315.64
7.0.240.0060.00315.43
7.0.230.0200.00015.55
7.0.220.0030.00615.38
7.0.210.0090.00615.39
7.0.200.0020.00616.23
7.0.190.0100.00315.52
7.0.180.0060.00915.45
7.0.170.0030.01015.35
7.0.160.0070.00715.56
7.0.150.0060.00615.62
7.0.140.0100.03318.94
7.0.130.0080.00815.75
7.0.120.0000.00815.54
7.0.110.0040.01115.34
7.0.100.0000.01215.54
7.0.90.0070.00715.58
7.0.80.0040.01215.47
7.0.70.0030.01015.49
7.0.60.0070.03317.86
7.0.50.0050.04516.82
7.0.40.0100.03016.95
7.0.30.0130.02816.79
7.0.20.0150.04416.83
7.0.10.0100.04016.83
7.0.00.0040.02916.86
5.6.380.0030.00614.38
5.6.370.0040.00814.63
5.6.360.0090.00014.68
5.6.350.0000.01014.67
5.6.340.0100.00314.36
5.6.330.0030.01014.68
5.6.320.0110.00414.58
5.6.310.0080.00814.41
5.6.300.0100.00014.57
5.6.290.0000.01414.58
5.6.280.0050.04117.86
5.6.270.0080.00614.34
5.6.260.0090.00314.48
5.6.250.0060.00614.29
5.6.240.0090.00614.64
5.6.230.0040.00714.23
5.6.220.0060.00714.41
5.6.210.0070.03217.57
5.6.200.0070.04316.37
5.6.190.0060.02417.45
5.6.180.0180.03517.58
5.6.170.0200.04517.49
5.6.160.0090.04417.69
5.6.150.0120.02916.43
5.6.140.0100.04016.40
5.6.130.0020.02516.41
5.6.120.0080.03917.69
5.6.110.0100.04217.84
5.6.100.0080.03717.90
5.6.90.0060.03517.87
5.6.80.0140.04017.58
5.6.70.0070.01114.52
5.6.60.0110.00414.54
5.6.50.0000.01314.28
5.6.40.0090.00614.48
5.6.30.0070.01014.56
5.6.20.0070.00714.64
5.6.10.0080.00814.36
5.6.00.0040.01614.43
5.5.380.0030.00311.41
5.5.370.0000.00611.00
5.5.360.0000.01311.45
5.5.350.0120.03416.04
5.5.340.0070.02114.72
5.5.330.0070.04515.84
5.5.320.0150.04215.97
5.5.310.0280.01815.84
5.5.300.0000.04314.75
5.5.290.0100.03914.74
5.5.280.0050.04916.13
5.5.270.0120.02516.15
5.5.260.0030.04716.18
5.5.250.0070.02116.10
5.5.240.0130.04115.71
5.5.230.0060.00611.36
5.5.220.0000.00910.96
5.5.210.0060.00311.28
5.5.200.0060.00511.07
5.5.190.0000.00811.00
5.5.180.0080.00811.23
5.5.170.0030.01011.32
5.5.160.0120.00311.26
5.5.150.0030.00310.90
5.5.140.0000.01011.02
5.5.130.0070.00711.00
5.5.120.0030.01011.13
5.5.110.0070.00711.29
5.5.100.0000.00811.13
5.5.90.0000.01011.38
5.5.80.0120.00411.16
5.5.70.0110.00711.25
5.5.60.0030.00711.35
5.5.50.0070.01010.93
5.5.40.0040.00411.07
5.5.30.0090.00611.27
5.5.20.0150.00011.14
5.5.10.0050.00311.29
5.5.00.0060.00011.22
5.4.450.0110.03815.35
5.4.440.0380.04615.45
5.4.430.0080.03915.32
5.4.420.0320.00615.30
5.4.410.0330.00515.26
5.4.400.0440.00414.98
5.4.390.0420.00315.05
5.4.380.0240.02814.68
5.4.370.0220.02715.03
5.4.360.0200.02814.95
5.4.350.0220.03014.83
5.4.340.0210.03214.84
5.4.330.0000.01311.01
5.4.320.0070.02211.73
5.4.310.0040.02311.83
5.4.300.0070.02011.81
5.4.290.0090.02111.80
5.4.280.0060.02211.68
5.4.270.0080.02411.66
5.4.260.0060.02211.74
5.4.250.0060.02111.63
5.4.240.0080.02011.76
5.4.230.0060.02111.70
5.4.220.0090.01911.74
5.4.210.0070.02011.70
5.4.200.0030.02311.71
5.4.190.0060.01911.68
5.4.180.0050.02211.61
5.4.170.0050.02411.62
5.4.160.0040.02511.81
5.4.150.0040.02111.59
5.4.140.0050.02211.61
5.4.130.0080.01911.61
5.4.120.0030.02111.56
5.4.110.0060.01911.49
5.4.100.0060.02011.36
5.4.90.0050.02311.56
5.4.80.0010.02511.52
5.4.70.0080.01911.64
5.4.60.0040.02011.67
5.4.50.0070.02211.56
5.4.40.0050.02211.53
5.4.30.0020.02411.56
5.4.20.0030.02411.47
5.4.10.0030.02211.54
5.4.00.0050.02011.19
5.3.290.0020.02611.52
5.3.280.0070.02011.33
5.3.270.0100.01711.48
5.3.260.0070.02211.44
5.3.250.0020.02711.51
5.3.240.0050.02311.39
5.3.230.0070.02111.42
5.3.220.0060.02011.37
5.3.210.0040.02111.42
5.3.200.0050.01911.41
5.3.190.0080.02011.35
5.3.180.0030.02211.46
5.3.170.0060.01911.37
5.3.160.0040.02111.49
5.3.150.0060.02211.48
5.3.140.0070.01811.46
5.3.130.0080.02111.49
5.3.120.0050.02011.46
5.3.110.0050.02311.46
5.3.100.0020.02311.19
5.3.90.0060.02111.18
5.3.80.0060.02111.13
5.3.70.0040.02211.04
5.3.60.0070.01611.03
5.3.50.0040.02211.00
5.3.40.0080.01811.09
5.3.30.0040.02110.94
5.3.20.0040.02110.82
5.3.10.0030.02110.81
5.3.00.0040.02210.81
5.2.170.0040.0189.55
5.2.160.0040.0179.55
5.2.150.0050.0169.55
5.2.140.0010.0189.55
5.2.130.0010.0189.53
5.2.120.0020.0189.53
5.2.110.0010.0199.53
5.2.100.0040.0159.53
5.2.90.0050.0169.53
5.2.80.0050.0179.53
5.2.70.0040.0209.53
5.2.60.0040.0179.51
5.2.50.0050.0169.49
5.2.40.0060.0199.48
5.2.30.0010.0219.47
5.2.20.0040.0189.46
5.2.10.0060.0149.42
5.2.00.0040.0199.35
5.1.60.0010.0149.00
5.1.50.0010.0179.00
5.1.40.0040.0158.98
5.1.30.0050.0159.16
5.1.20.0040.0159.17
5.1.10.0040.0159.03
5.1.00.0020.0169.03
5.0.50.0080.0108.27
5.0.40.0030.0148.20
5.0.30.0040.0168.11
5.0.20.0030.0128.10
5.0.10.0020.0128.09
5.0.00.0030.0168.09
4.4.90.0010.0107.34
4.4.80.0010.0127.32
4.4.70.0040.0097.33
4.4.60.0040.0107.33
4.4.50.0030.0097.33
4.4.40.0010.0167.30
4.4.30.0010.0117.33
4.4.20.0030.0087.37
4.4.10.0030.0077.38
4.4.00.0050.0117.33
4.3.110.0020.0097.28
4.3.100.0030.0087.28
4.3.90.0010.0117.27
4.3.80.0030.0137.24
4.3.70.0050.0067.26
4.3.60.0030.0097.26
4.3.50.0040.0107.26
4.3.40.0010.0157.22
4.3.30.0010.0116.62
4.3.20.0040.0106.61
4.3.10.0010.0116.58
4.3.00.0020.01112.75

preferences:
50.1 ms | 401 KiB | 5 Q