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 */
Output for git.master, rfc.property-hooks
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: Out of memory (allocated 27271168 bytes) (tried to allocate 16777224 bytes) in /in/XKHV4 on line 48 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.
Output for git.master_jit
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: Out of memory (allocated 10489856 bytes) (tried to allocate 16777224 bytes) in /in/XKHV4 on line 40 mmap() failed: [12] Cannot allocate memory mmap() failed: [12] Cannot allocate memory
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.7 ms | 402 KiB | 8 Q