3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = ['1613938511.464898123456789', '1613938511.464898923456789', '1613938511.123456789', '1613938511.12345678910', '1613938519.123456789', '1613938511.999999', '1613938511.999999999999']; foreach ($tests as $test) { echo "Testing : $test\n"; $f = (float)$test; // echo " string=" . $f . " | json =" . json_encode($f); $jsonOne = substr(json_encode($f),0,17); $testOne = substr($test,0,17); echo "\n> Test passed :" . $jsonOne ." =?= ". $testOne . " ::: " . ($jsonOne === $testOne ? 'yes' : 'no'); echo "\n-------------------------------------------------\n"; } // more complex testing $test1MResults = []; $testFailed = []; for ($i = 0; $i < 1000000; $i++) { $testFloat = '1613938511.' . $i; $floatN = (float) $testFloat; $jsonN = json_encode($floatN); $floatJsonN = (float) $jsonN; $absN = (int) abs($floatN - $floatJsonN) * 1000000; /** * Why using or when compare text faild ? because json delete the zero at end of a float , but in our testFloat its composed string 'xx'.$i (10) * Why using int comparasion ? to strict verify that $floatN === $floatJsonN with the 6 digits * * You can play with conditions to see example of fails (that are not really a fail but just a wrong comparasion method) */ $passed = ($jsonN === $testFloat || $absN === 0); $test1MResults[] = $passed; if (false === $passed) { $testFailed[] = [$i, $jsonN, $testFloat, $absN, gettype($absN)]; } } $totalTests = count($test1MResults); $totalSuccess = count(array_filter($test1MResults)); $totalFails = $totalTests - $totalSuccess; print_r("Total Success : " . $totalSuccess . "\n"); print_r("Total Fails : " . ($totalFails) . "\n"); if ($totalFails > 0) { $maxShow = 10 > $totalFails ? $totalFails : 10; for ($i=0; $i < $maxShow; $i++) { print_r(json_encode($testFailed[$i])); echo "\n"; } for ($i=$totalFails; $i > $totalFails - $maxShow; $i--) { print_r(json_encode($testFailed[$i])); echo "\n"; } } echo "\n\n"; /** * Total Success : 1000000 * Total Fails : 0 */

Abusive script

This script was stopped while abusing our resources

Output for 7.1.5 - 7.1.6, 7.1.9 - 7.1.10, 7.1.13 - 7.1.15, 7.1.17 - 7.1.19, 7.1.26 - 7.1.27, 7.1.29, 7.2.1 - 7.2.6, 7.2.11 - 7.2.16, 7.2.19, 7.2.27, 7.2.30 - 7.2.32, 7.2.34, 7.3.0 - 7.3.2, 7.3.4 - 7.3.5, 7.3.7, 7.3.10 - 7.3.13, 7.3.16 - 7.3.21, 7.3.23 - 7.3.27, 7.4.0, 7.4.4, 7.4.6 - 7.4.11, 7.4.13 - 7.4.16, 8.0.0 - 8.0.3
Testing : 1613938511.464898123456789 > Test passed :1613938511.464898 =?= 1613938511.464898 ::: yes ------------------------------------------------- Testing : 1613938511.464898923456789 > Test passed :1613938511.464898 =?= 1613938511.464898 ::: yes ------------------------------------------------- Testing : 1613938511.123456789 > Test passed :1613938511.123456 =?= 1613938511.123456 ::: yes ------------------------------------------------- Testing : 1613938511.12345678910 > Test passed :1613938511.123456 =?= 1613938511.123456 ::: yes ------------------------------------------------- Testing : 1613938519.123456789 > Test passed :1613938519.123456 =?= 1613938519.123456 ::: yes ------------------------------------------------- Testing : 1613938511.999999 > Test passed :1613938511.999999 =?= 1613938511.999999 ::: yes ------------------------------------------------- Testing : 1613938511.999999999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 33554440 bytes) in /in/XKHV4 on line 48
Process exited with code 255.
Output for 7.2.17, 7.4.12
Testing : 1613938511.464898123456789 > Test passed :1613938511.464898 =?= 1613938511.464898 ::: yes ------------------------------------------------- Testing : 1613938511.464898923456789 > Test passed :1613938511.464898 =?= 1613938511.464898 ::: yes ------------------------------------------------- Testing : 1613938511.123456789 > Test passed :1613938511.123456 =?= 1613938511.123456 ::: yes ------------------------------------------------- Testing : 1613938511.12345678910 > Test passed :1613938511.123456 =?= 1613938511.123456 ::: yes ------------------------------------------------- Testing : 1613938519.123456789 > Test passed :1613938519.123456 =?= 1613938519.123456 ::: yes ------------------------------------------------- Testing : 1613938511.999999 > Test passed :1613938511.999999 =?= 1613938511.999999 ::: yes ------------------------------------------------- Testing : 1613938511.999999999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 33554440 bytes) in /in/XKHV4 on line 48
Process exited with code 137.
Output for 7.1.0 - 7.1.4, 7.1.7 - 7.1.8, 7.1.11 - 7.1.12, 7.1.16, 7.1.20 - 7.1.25, 7.1.28, 7.1.30 - 7.1.33, 7.2.0, 7.2.7 - 7.2.10, 7.2.18, 7.2.20 - 7.2.26, 7.2.28 - 7.2.29, 7.2.33, 7.3.3, 7.3.6, 7.3.8 - 7.3.9, 7.3.14 - 7.3.15, 7.3.22, 7.4.1 - 7.4.3, 7.4.5
Testing : 1613938511.464898123456789 > Test passed :1613938511.464898 =?= 1613938511.464898 ::: yes ------------------------------------------------- Testing : 1613938511.464898923456789 > Test passed :1613938511.464898 =?= 1613938511.464898 ::: yes ------------------------------------------------- Testing : 1613938511.123456789 > Test passed :1613938511.123456 =?= 1613938511.123456 ::: yes ------------------------------------------------- Testing : 1613938511.12345678910 > Test passed :1613938511.123456 =?= 1613938511.123456 ::: yes ------------------------------------------------- Testing : 1613938519.123456789 > Test passed :1613938519.123456 =?= 1613938519.123456 ::: yes ------------------------------------------------- Testing : 1613938511.999999 > Test passed :1613938511.999999 =?= 1613938511.999999 ::: yes ------------------------------------------------- Testing : 1613938511.999999999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no -------------------------------------------------
Process exited with code 137.
Output for 7.0.0 - 7.0.9, 7.0.11 - 7.0.33
Testing : 1613938511.464898123456789 > Test passed :1613938511.4649 =?= 1613938511.464898 ::: no ------------------------------------------------- Testing : 1613938511.464898923456789 > Test passed :1613938511.4649 =?= 1613938511.464898 ::: no ------------------------------------------------- Testing : 1613938511.123456789 > Test passed :1613938511.1235 =?= 1613938511.123456 ::: no ------------------------------------------------- Testing : 1613938511.12345678910 > Test passed :1613938511.1235 =?= 1613938511.123456 ::: no ------------------------------------------------- Testing : 1613938519.123456789 > Test passed :1613938519.1235 =?= 1613938519.123456 ::: no ------------------------------------------------- Testing : 1613938511.999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Testing : 1613938511.999999999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 33554440 bytes) in /in/XKHV4 on line 48
Process exited with code 255.
Output for 7.0.10
Testing : 1613938511.464898123456789 > Test passed :1613938511.4649 =?= 1613938511.464898 ::: no ------------------------------------------------- Testing : 1613938511.464898923456789 > Test passed :1613938511.4649 =?= 1613938511.464898 ::: no ------------------------------------------------- Testing : 1613938511.123456789 > Test passed :1613938511.1235 =?= 1613938511.123456 ::: no ------------------------------------------------- Testing : 1613938511.12345678910 > Test passed :1613938511.1235 =?= 1613938511.123456 ::: no ------------------------------------------------- Testing : 1613938519.123456789 > Test passed :1613938519.1235 =?= 1613938519.123456 ::: no ------------------------------------------------- Testing : 1613938511.999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Testing : 1613938511.999999999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no -------------------------------------------------
Process exited with code 137.
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Testing : 1613938511.464898123456789 > Test passed :1613938511.4649 =?= 1613938511.464898 ::: no ------------------------------------------------- Testing : 1613938511.464898923456789 > Test passed :1613938511.4649 =?= 1613938511.464898 ::: no ------------------------------------------------- Testing : 1613938511.123456789 > Test passed :1613938511.1235 =?= 1613938511.123456 ::: no ------------------------------------------------- Testing : 1613938511.12345678910 > Test passed :1613938511.1235 =?= 1613938511.123456 ::: no ------------------------------------------------- Testing : 1613938519.123456789 > Test passed :1613938519.1235 =?= 1613938519.123456 ::: no ------------------------------------------------- Testing : 1613938511.999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Testing : 1613938511.999999999999 > Test passed :1613938512 =?= 1613938511.999999 ::: no ------------------------------------------------- Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 32 bytes) in /in/XKHV4 on line 31
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/XKHV4 on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/XKHV4 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/XKHV4 on line 4
Process exited with code 255.

preferences:
48.53 ms | 471 KiB | 5 Q