3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyDateTime extends \DateTime { public function add($interval) { $oldDay = (int)$this->format('d'); $this->setDate((int)$this->format('Y'), (int)$this->format('m'), 1); parent::add($interval); $maxDay = (int)$this->format('t'); if($oldDay > $maxDay){ $this->setDate((int)$this->format('Y'), (int)$this->format('m'), $maxDay); } else { $this->setDate((int)$this->format('Y'), (int)$this->format('m'), $oldDay); } return $this; } public function sub($interval) { $oldDay = (int)$this->format('d'); $this->setDate((int)$this->format('Y'), (int)$this->format('m'), 1); parent::sub($interval); $maxDay = (int)$this->format('t'); if($oldDay > $maxDay){ $this->setDate((int)$this->format('Y'), (int)$this->format('m'), $maxDay); } else { $this->setDate((int)$this->format('Y'), (int)$this->format('m'), $oldDay); } return $this; } } $myDateTime = new MyDateTime('30th November 2000'); $interval = new \DateInterval('P3M'); var_dump($myDateTime->add($interval));
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of MyDateTime::add($interval) should either be compatible with DateTime::add(DateInterval $interval): DateTime, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/MU8WF on line 4 Deprecated: Return type of MyDateTime::sub($interval) should either be compatible with DateTime::sub(DateInterval $interval): DateTime, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/MU8WF on line 18 object(MyDateTime)#1 (3) { ["date"]=> string(26) "2001-02-28 00:00: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:
28.81 ms | 402 KiB | 8 Q