3v4l.org

run code in 300+ PHP versions simultaneously
<?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); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
'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" } '30 '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" } '30 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-06-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 '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" } '30 '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" } '30 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-06-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.0.29, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30
'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 7.3.32 - 7.3.33, 8.0.13
'4 ''30 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-02-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } '28 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-03-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } '30 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-04-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } '29 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-05-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } '30 'object(DateTime)#1 (3) { ["date"]=> string(26) "2016-06-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for 5.5.0 - 5.5.38
'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.3.29, 5.4.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.0.5, 5.1.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.3.11, 4.4.0 - 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.

preferences:
293.63 ms | 401 KiB | 397 Q