3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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.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