3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $currentDate = new DateTime('2016-01-01'); $reportEndDate = new DateTime('2016-05-31'); $months = $currentDate->diff($reportEndDate)->m; var_export($months."\n"); for ($i = 0; $i <= $months ; $i++) { $currentDateImmutable = \DateTimeImmutable::createFromMutable($currentDate); $daysUntilNextMonth = $currentDateImmutable->diff($currentDateImmutable->modify('last day of this month'))->d; var_export($daysUntilNextMonth."\n"); for ($j = 0; $j <= $daysUntilNextMonth ; $j++) { $currentDate->modify('+1 day'); } var_dump($currentDate); }
based on G0Y3h
Output for 5.6.0 - 5.6.30, hhvm-3.13.2 - 3.22.0, 7.0.0 - 7.3.0beta1
'4 ''30 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-02-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } '28 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } '1 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-03 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } '28 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } '29 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for hhvm-3.11.1 - 3.12.14
'4 ' Fatal error: Uncaught Error: Call to undefined method DateTimeImmutable::createFromMutable() in /in/7X1jQ:12 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.5.0 - 5.5.38, hhvm-3.10.1
'4 ' Fatal error: Call to undefined method DateTimeImmutable::createFromMutable() in /in/7X1jQ on line 12
Process exited with code 255.
Output for 5.3.0 - 5.4.45
'4 ' Fatal error: Class 'DateTimeImmutable' not found in /in/7X1jQ on line 12
Process exited with code 255.
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/7X1jQ on line 12 Fatal error: Call to undefined method DateTime::diff() in /in/7X1jQ on line 6
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/7X1jQ on line 12 Fatal error: Class 'DateTime' not found in /in/7X1jQ on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/7X1jQ on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/7X1jQ on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/7X1jQ on line 6
Process exited with code 255.