3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nextMonth($thisMonth, $monthInc) { $firstOfThis = date("Y-m", strtotime($thisMonth)); $dNow = date("t", strtotime($thisMonth)); $dNext = date("t", strtotime($firstOfThis . " +1 month")); $dDay = date("d", strtotime($thisMonth)); $output = date("Y-m-d",strtotime($thisMonth . " +1 month")); if ($dNext < $dNow && $dNext < $dDay) { $nextMonth = date("Y-m", strtotime($thisMonth)); $nextMonth = date("Y-m", strtotime($nextMonth . " +1 month")); $output = $nextMonth . '-' . $dNext; } return $output; } echo nextMonth("2010-01-31",1); $sample1 = "2010-01-31"; $sample1a = "2010-01-01"; $dnow = date("t",strtotime($sample1)); $dnext = date("t",strtotime($sample1a . " +1 month")); $dday = date("d",strtotime($sample1)); $output = date("Y-m-d",strtotime($sample1 . " +1 month")); echo '/' . $dnow . '/' . $dnext . '/' . $dday . '/'; echo "\n"; if ($dnext < $dnow && $dnext < $dday) { $nextMonth = date("Y-m", strtotime($sample1)); $nextMonth = date("Y-m", strtotime($nextMonth . " +1 month")); $output = $nextMonth . '-' . $dnext; } echo $output; echo "\n"; $ts = strtotime('2010-01-31 +1 month'); echo date('Y-m-d', $ts); echo "\n"; $dt = new \DateTime('2010-01-31'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d'); echo "\n"; $ts = strtotime('2010-01-05 +1 month'); echo date('Y-m-d', $ts); echo "\n"; $dt = new \DateTime('2010-01-05'); $dt->add(new \DateInterval('P1M')); echo $dt->format('Y-m-d');
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
2010-02-28/31/28/31/ 2010-02-28 2010-03-03 2010-03-03 2010-02-05 2010-02-05
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 41 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 42 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 48 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 49 2010-02-28/31/28/31/ 2010-02-28 2010-03-03 Fatal error: Call to undefined method DateTime::add() in /in/AYdN1 on line 42
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 41 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 42 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 48 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 49 2010-03-03/31/28/31/ 2013-12-28 2010-03-03 Fatal error: Class 'DateTime' not found in /in/AYdN1 on line 41
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 41 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 42 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 48 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 49 2010-03-03/31/28/31/ 2010-01-28 2010-03-03 Fatal error: Class 'DateTime' not found in /in/AYdN1 on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 41 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 42 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 48 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 49 2010-03-03/31/28/31/ 2010-01-28 2010-03-03 Fatal error: Cannot instantiate non-existent class: datetime in /in/AYdN1 on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 41 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 42 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 48 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/AYdN1 on line 49 2010-03-03/31/28/31/ 2010-01-28 2010-03-03 Fatal error: Cannot instantiate non-existent class: datetime in /in/AYdN1 on line 41

preferences:
267.73 ms | 402 KiB | 365 Q