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)->format('t'); $thirtyFirstOfNextMonth = clone $firstOfDateMonth; $thirtyFirstOfNextMonth->modify('+' . (int) $increment . ' month')->format('t'); $dayOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->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/9oHCL:6 Stack trace: #0 /in/9oHCL(22): nextMonth('2009-12-31', 2) #1 {main} thrown in /in/9oHCL on line 6
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught Error: Call to a member function format() on false in /in/9oHCL:6 Stack trace: #0 /in/9oHCL(22): nextMonth('2009-12-31', 2) #1 {main} thrown in /in/9oHCL on line 6
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:
41.32 ms | 401 KiB | 8 Q