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.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.11, 8.1rc1 - rc2
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.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.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:
66.97 ms | 482 KiB | 5 Q