3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class MyDateTime extends \DateTime { public function add(DateInterval $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(DateInterval $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 2012'); $interval = new \DateInterval('P3M'); var_dump($myDateTime->add($interval))
Output for 5.4.0 - 5.4.17
Strict Standards: Declaration of MyDateTime::add() should be compatible with DateTime::add($interval) in /in/D7p1m on line 31 Strict Standards: Declaration of MyDateTime::sub() should be compatible with DateTime::sub($interval) in /in/D7p1m on line 31 Parse error: syntax error, unexpected end of file in /in/D7p1m on line 35
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Strict Standards: Declaration of MyDateTime::add() should be compatible with that of DateTime::add() in /in/D7p1m on line 31 Strict Standards: Declaration of MyDateTime::sub() should be compatible with that of DateTime::sub() in /in/D7p1m on line 31 Parse error: syntax error, unexpected $end in /in/D7p1m on line 35
Process exited with code 255.