3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nextMonth($date, $increment) { $firstOfDateMonth = \DateTime::createFromFormat('Y-m-01', $date); $thirtyFirstOfDateMonth = \DateTime::createFromFormat('Y-m-t', $date); $thirtyFirstOfDateMonth = $thirtyFirstOfDateMonth->format('t'); $thirtyFirstOfNextMonth = clone $firstOfDateMonth; $thirtyFirstOfNextMonth->modify('+' . (int) $increment . ' month'); $thirtyFirstOfNextMonth = $thirtyFirstOfNextMonth->format('t'); $dayOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date); $dayOfDateMonth = $dayOfDateMonth->format('d'); $dt = \DateTime::createFromFormat('Y-m-d', $date); $dt->modify('+' . (int) $increment . ' month'); if ($thirtyFirstOfNextMonth < $thirtyFirstOfDateMonth && $thirtyFirstOfNextMonth < $dayOfDateMonth) { $dt = clone $firstOfDateMonth; $dt->modify('+' . (int) $increment . ' month +' . $thirtyFirstOfNextMonth); } return $dt->format('Y-m-d'); } echo nextMonth('2009-12-31', 2),"\n"; echo nextMonth('2010-01-31', 1),"\n"; echo nextMonth('2010-01-05', 1),"\n"; echo nextMonth('2010-12-05', 1),"\n";
Output for git.master, git.master_jit
Fatal error: Uncaught Error: Call to a member function format() on bool in /in/JTcAg:7 Stack trace: #0 /in/JTcAg(25): nextMonth('2009-12-31', 2) #1 {main} thrown in /in/JTcAg on line 7
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught Error: Call to a member function format() on false in /in/JTcAg:7 Stack trace: #0 /in/JTcAg(25): nextMonth('2009-12-31', 2) #1 {main} thrown in /in/JTcAg on line 7
Process exited with code 255.

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