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('+' . $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('+' . $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 5.4.0 - 5.4.22
Parse error: syntax error, unexpected '(int)' (int) (T_INT_CAST) in /in/EZPNf on line 14
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_INT_CAST in /in/EZPNf on line 14
Process exited with code 255.

preferences:
181.24 ms | 1386 KiB | 58 Q