3v4l.org

run code in 300+ PHP versions simultaneously
<?php $datetime1 = new \DateTimeImmutable('9999-01-02 15:00:00.000000', new \DateTimeZone('UTC')); try { $datetime2 = $datetime1->add(new \DateInterval('P1Y')); echo $datetime2->format('Y-m-d H:i:s.u') . \PHP_EOL; } catch (\Throwable $e) { echo 'exception' . \PHP_EOL; } $datetime3 = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s.u', $datetime2->format('Y-m-d H:i:s.u'), new \DateTimeZone('UTC')); if ($datetime3 !== false) { echo $datetime3->format('Y-m-d H:i:s.u') . \PHP_EOL; } else { echo 'false' . \PHP_EOL; } try { $datetime4 = new \DateTimeImmutable($datetime2->format('Y-m-d H:i:s.u'), new \DateTimeZone('UTC')); echo $datetime4->format('Y-m-d H:i:s.u') . \PHP_EOL; } catch (\Throwable $e) { echo 'exception' . \PHP_EOL; } // Workaround with fake year try { $datetime5 = new \DateTimeImmutable($datetime2->format('1234-m-d H:i:s.u'), new \DateTimeZone('UTC')); $datetime5 = $datetime5->setDate((int)$datetime2->format("Y"), (int)$datetime2->format("n"), (int)$datetime2->format("j")); echo $datetime5->format('Y-m-d H:i:s.u') . \PHP_EOL; } catch (\Throwable $e) { echo 'exception' . \PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
10000-01-02 15:00:00.000000 false exception 10000-01-02 15:00:00.000000

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:
65.65 ms | 401 KiB | 8 Q