3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = static function (string $expected, int $precision): void { $date = DateTimeImmutable::createFromFormat('U.u', $expected); echo 'Testing "', $date->format('Y-m-d H:i:s.u'), '" with given precision (', $precision, ')', PHP_EOL; ini_set('serialize_precision', $precision); $encoded = json_encode((float) $date->format('U.u')); var_dump($expected, $encoded, $expected === $encoded); if ($expected === $encoded) { echo PHP_EOL; return; } $adjustedPrecision = strlen($date->format('Uu')); echo 'Testing with adjusted precision (', $adjustedPrecision, ')', PHP_EOL; ini_set('serialize_precision', $adjustedPrecision); $encoded = json_encode((float) $date->format('U.u')); var_dump($expected, $encoded, $expected === $encoded); echo PHP_EOL; }; // $test('1487285080.123456', 8); // $test('1487285080.123456', 16); // $test('11487285080.123456', 16); // $test('112487285080.123456', -1); // $test('9999999999.999999', -1); $test('9999999999.999994', -1); $test('9999999999.999995', -1);
Output for 7.1.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
Testing "2286-11-20 17:46:39.999994" with given precision (-1) string(17) "9999999999.999994" string(17) "9999999999.999994" bool(true) Testing "2286-11-20 17:46:39.999995" with given precision (-1) string(17) "9999999999.999995" string(17) "9999999999.999994" bool(false) Testing with adjusted precision (16) string(17) "9999999999.999995" string(17) "9999999999.999994" bool(false)
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 7.0.33
Testing "2286-11-20 17:46:39.999994" with given precision (-1) string(17) "9999999999.999994" string(11) "10000000000" bool(false) Testing with adjusted precision (16) string(17) "9999999999.999994" string(11) "10000000000" bool(false) Fatal error: Uncaught TypeError: Return value of {closure}() must be an instance of void, none returned in /in/0jE0W:31 Stack trace: #0 /in/0jE0W(38): {closure}('9999999999.9999...', -1) #1 {main} thrown in /in/0jE0W on line 31
Process exited with code 255.

preferences:
131.17 ms | 409 KiB | 5 Q