3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new DateTimeImmutable('2021-03-18 14:38:45.008455'); $time = (float) $obj->format('U.u'); $recreated = DateTimeImmutable::createFromFormat('U.u', json_encode($time)); var_dump($obj, $recreated, $recreated == $obj); $json = json_encode(['expire'=> $time] , JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR); $afterDecoded = json_decode($json, true, 512, JSON_THROW_ON_ERROR); $time = $afterDecoded['expire']; $recreated = DateTimeImmutable::createFromFormat('U.u', json_encode($time)); var_dump($obj, $recreated, $recreated == $obj);
Output for 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true)
Output for 7.3.32, 7.4.26, 8.0.13
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } object(DateTimeImmutable)#3 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true)
Output for 7.2.0 - 7.2.34
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) Warning: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' (this will throw an Error in a future version of PHP) in /in/cAFijB on line 10 Warning: A non-numeric value encountered in /in/cAFijB on line 10 Warning: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' (this will throw an Error in a future version of PHP) in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be integer, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 7.1.0 - 7.1.33
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008455" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Warning: A non-numeric value encountered in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be integer, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 7.0.4 - 7.0.33
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008500" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(false) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be integer, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 7.0.0 - 7.0.3
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008500" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be integer, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 5.6.19 - 5.6.40
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008500" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(false) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be long, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 5.5.14 - 5.5.38, 5.6.0 - 5.6.18
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2021-03-18 13:38:45.008500" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be long, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2021-03-18 14:38:45.008455" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 5.5.4 - 5.5.13
object(DateTimeImmutable)#1 (3) { ["date"]=> string(19) "2021-03-18 14:38:45" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(19) "2021-03-18 13:38:45" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(true) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be long, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(19) "2021-03-18 14:38:45" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 5.5.0 - 5.5.3
object(DateTimeImmutable)#1 (3) { ["date"]=> string(19) "2021-03-18 14:38:45" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(19) "2021-03-18 13:38:45" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } bool(false) Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 10 Notice: Use of undefined constant JSON_THROW_ON_ERROR - assumed 'JSON_THROW_ON_ERROR' in /in/cAFijB on line 12 Warning: json_decode() expects parameter 4 to be long, string given in /in/cAFijB on line 12 object(DateTimeImmutable)#1 (3) { ["date"]=> string(19) "2021-03-18 14:38:45" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for 5.4.0 - 5.4.45
Fatal error: Class 'DateTimeImmutable' not found in /in/cAFijB on line 3
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 '[', expecting ')' in /in/cAFijB on line 10
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 '[', expecting ')' in /in/cAFijB on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/cAFijB on line 10
Process exited with code 255.

preferences:
332.02 ms | 401 KiB | 465 Q