3v4l.org

run code in 300+ PHP versions simultaneously
<?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 + 0.5 days' => 60 * 60 * 24 + 12 * 60 * 60, '1 month' => '?' ); foreach ($intervals as $interval => $expected) { if (is_numeric($interval)) { $found = (int) $interval; } else { $zeroDate = new \DateTime(); // can't use @0, it will add 3600 seconds to final output on php 5.3.9 - 5.4.7 $zeroDate->setTimestamp(0); $zeroDate->add(\DateInterval::createFromDateString($interval)); $found = $zeroDate->getTimestamp(); } echo sprintf("found %s expected %s\n", $found, $expected); }
Output for 8.3.0 - 8.3.6
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 Fatal error: Uncaught DateMalformedIntervalStringException: Unknown or bad format (1 day + 0.5 days) at position 6 (+): Unexpected character in /in/EJJNu:22 Stack trace: #0 /in/EJJNu(22): DateInterval::createFromDateString('1 day + 0.5 day...') #1 {main} thrown in /in/EJJNu on line 22
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
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 Warning: DateInterval::createFromDateString(): Unknown or bad format (1 day + 0.5 days) at position 6 (+): Unexpected character in /in/EJJNu on line 22 Fatal error: Uncaught TypeError: DateTime::add(): Argument #1 ($interval) must be of type DateInterval, bool given in /in/EJJNu:22 Stack trace: #0 /in/EJJNu(22): DateTime->add(false) #1 {main} thrown in /in/EJJNu on line 22
Process exited with code 255.
Output for 7.3.4 - 7.3.33, 7.4.0 - 7.4.33
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 Warning: DateInterval::createFromDateString(): Unknown or bad format (1 day + 0.5 days) at position 6 (+): Unexpected character in /in/EJJNu on line 22 Warning: DateTime::add() expects parameter 1 to be DateInterval, bool given in /in/EJJNu on line 22 found 0 expected 129600 found 2678400 expected ?
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.13, 7.3.0 - 7.3.3
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 86400 expected 129600 found 2678400 expected ?
Output for 7.2.17 - 7.2.33
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 Warning: DateInterval::createFromDateString(): Unknown or bad format (1 day + 0.5 days) at position 6 (+): Unexpected character in /in/EJJNu on line 22 Warning: DateTime::add() expects parameter 1 to be DateInterval, boolean given in /in/EJJNu on line 22 found 0 expected 129600 found 2678400 expected ?
Output for 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/EJJNu on line 19 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/EJJNu on line 22 found 0 expected 0 found 86400 expected 86400 Fatal error: Call to undefined method DateTime::setTimestamp() in /in/EJJNu on line 21
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/EJJNu on line 19 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/EJJNu on line 22 found 0 expected 0 found 86400 expected 86400 Fatal error: Class 'DateTime' not found in /in/EJJNu on line 19
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/EJJNu on line 19 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/EJJNu on line 22 found 0 expected 0 found 86400 expected 86400 Fatal error: Cannot instantiate non-existent class: datetime in /in/EJJNu on line 19
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/EJJNu on line 19 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/EJJNu on line 22 found 0 expected 0 found 86400 expected 86400 Fatal error: Cannot instantiate non-existent class: datetime in /in/EJJNu on line 19

preferences:
293.99 ms | 402 KiB | 452 Q