3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $intervals = array( '0' => 0, '86400' => 86400, '0 second' => 0, '1 second' => 1, '1 minute' => 60, '1 hour' => 60 * 60, '1 day' => 60 * 60 * 24, '1 year' => 60 * 60 * 24 * 365, '1 day + 12 hours' => 60 * 60 * 24 + 12 * 60 * 60 ); foreach ($intervals as $interval => $expected) { if (is_numeric($interval)) { $found = (int) $interval; } else { $zeroDate = new \DateTime('@0'); // bug fix for php 5.3.9 - 5.4.7 $zeroDate->modify(sprintf('- %s seconds', $zeroDate->getTimestamp())); $zeroDate->add(\DateInterval::createFromDateString($interval)); $found = $zeroDate->getTimestamp(); } echo sprintf("found %s expected %s\n", $found, $expected); }
Output for 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
found 0 expected 0 found 86400 expected 86400 found 0 expected 0 found 1 expected 1 found 60 expected 60 found 3600 expected 3600 found 86400 expected 86400 found 31536000 expected 31536000 found 129600 expected 129600
Output for 5.4.0 - 5.4.45
found 0 expected 0 found 86400 expected 86400 Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /in/YnZt1:18 Stack trace: #0 /in/YnZt1(18): DateTime->__construct('@0') #1 {main} thrown in /in/YnZt1 on line 18
Process exited with code 255.
Output for 5.3.0 - 5.3.29
found 0 expected 0 found 86400 expected 86400 Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead' in /in/YnZt1:18 Stack trace: #0 /in/YnZt1(18): DateTime->__construct('@0') #1 {main} thrown in /in/YnZt1 on line 18
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/YnZt1 on line 18 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/YnZt1 on line 21 found 0 expected 0 found 86400 expected 86400 Fatal error: Call to undefined method DateTime::getTimestamp() in /in/YnZt1 on line 20
Process exited with code 255.
Output for 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>18</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>21</b><br /> found 0 expected 0 found 86400 expected 86400 <br /> <b>Fatal error</b>: Call to undefined method DateTime::getTimestamp() in <b>/in/YnZt1</b> on line <b>20</b><br />
Process exited with code 255.
Output for 5.0.0 - 5.1.6
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>18</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>21</b><br /> found 0 expected 0 found 86400 expected 86400 <br /> <b>Fatal error</b>: Class 'DateTime' not found in <b>/in/YnZt1</b> on line <b>18</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.4.9
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>18</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>21</b><br /> found 0 expected 0 found 86400 expected 86400 <br /> <b>Fatal error</b>: Cannot instantiate non-existent class: datetime in <b>/in/YnZt1</b> on line <b>18</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>18</b><br /> <br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/YnZt1</b> on line <b>21</b><br /> found 0 expected 0 found 86400 expected 86400 <br /> <b>Fatal error</b>: Cannot instantiate non-existent class: datetime in <b>/in/YnZt1</b> on line <b>18</b><br />