3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyEntity { public ?int $id = null; public ?\DateTimeImmutable $updatedAt = null; public function setUpdatedAt(): self { if (null !== $this->id || null === $this->updatedAt) { $this->updatedAt = new DateTimeImmutable(); } return $this; } } // Insert without custom date $a = new MyEntity(); $a->setUpdatedAt(); var_dump($a); // Insert with custom date $b = new MyEntity(); $b->updatedAt = new \DateTimeImmutable('2022-09-16'); $b->setUpdatedAt(); var_dump($b); // Update $c = new MyEntity(); $c->id = 42; $c->updatedAt = new \DateTimeImmutable('2022-09-16'); $c->setUpdatedAt(); var_dump($c);
Output for git.master
object(MyEntity)#1 (2) { ["id"]=> NULL ["updatedAt"]=> object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2023-10-19 14:18:35.004212" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(MyEntity)#3 (2) { ["id"]=> NULL ["updatedAt"]=> object(DateTimeImmutable)#4 (3) { ["date"]=> string(26) "2022-09-16 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(MyEntity)#5 (2) { ["id"]=> int(42) ["updatedAt"]=> object(DateTimeImmutable)#7 (3) { ["date"]=> string(26) "2023-10-19 14:18:35.004314" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } }
Output for git.master_jit
object(MyEntity)#1 (2) { ["id"]=> NULL ["updatedAt"]=> object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2023-10-19 14:18:35.008701" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(MyEntity)#3 (2) { ["id"]=> NULL ["updatedAt"]=> object(DateTimeImmutable)#4 (3) { ["date"]=> string(26) "2022-09-16 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(MyEntity)#5 (2) { ["id"]=> int(42) ["updatedAt"]=> object(DateTimeImmutable)#7 (3) { ["date"]=> string(26) "2023-10-19 14:18:35.008888" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } }
Output for rfc.property-hooks
object(MyEntity)#1 (2) { ["id"]=> NULL ["updatedAt"]=> object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2023-10-19 14:18:35.005373" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(MyEntity)#3 (2) { ["id"]=> NULL ["updatedAt"]=> object(DateTimeImmutable)#4 (3) { ["date"]=> string(26) "2022-09-16 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(MyEntity)#5 (2) { ["id"]=> int(42) ["updatedAt"]=> object(DateTimeImmutable)#7 (3) { ["date"]=> string(26) "2023-10-19 14:18:35.005497" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } }

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.44 ms | 411 KiB | 5 Q