3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ContractVersion { private $end_date; public function __construct(\DateTime $end_date) { $this->end_date = $end_date; } public function getEndDate(): \DateTime { return clone $this->end_date; } } class VersionedContract { private $versions = []; public function __construct(\DateTime $end_date) { $this->versions[] = new ContractVersion($end_date); } public function getEndDate(): \DateTime { return $this->getCurrentVersion()->getEndDate(); } private function getCurrentVersion(): ContractVersion { return end($this->versions); } public function renew(\DateInterval $interval) { $this->versions[] = new ContractVersion($this->getEndDate()->add($interval)); } } $contract = new VersionedContract(new \DateTime('2017-10-10 10:10:00')); var_dump($contract->getEndDate()); // string(26) "2017-10-10 10:10:00.000000" $endDate = $contract->getEndDate(); var_dump($endDate); // same string(26) "2017-10-10 10:10:00.000000" $endDate->add(new \DateInterval('P1Y')); var_dump($endDate);
Output for git.master, git.master_jit, rfc.property-hooks
object(DateTime)#4 (3) { ["date"]=> string(26) "2017-10-10 10:10:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#4 (3) { ["date"]=> string(26) "2017-10-10 10:10:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#4 (3) { ["date"]=> string(26) "2018-10-10 10:10:00.000000" ["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:
46.12 ms | 402 KiB | 8 Q