3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "blah 2015 yar"; $pos = strpos($string, "20"); $year = substr($string, $pos, 4); $end_year = "12/31/" . $year; echo $end_year; $end_time = new DateTime($end_year); var_dump($end_time); $start_time = new DateTime(); var_dump($start_time); $date1 = $end_time->date; $date2 = $start_time->date; $diff = $date1->diff($date2); var_dump($diff); ?>
based on V1Z2b
Output for 7.1.0
12/31/2015object(DateTime)#1 (3) { ["date"]=> string(26) "2015-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(26) "2014-10-02 22:30:45.004070" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Uncaught Error: Call to a member function diff() on string in /in/2W2At:14 Stack trace: #0 {main} thrown in /in/2W2At on line 14
Process exited with code 255.
Output for 7.0.0 - 7.0.14
12/31/2015object(DateTime)#1 (3) { ["date"]=> string(26) "2015-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(26) "2014-10-02 22:30:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Uncaught Error: Call to a member function diff() on string in /in/2W2At:14 Stack trace: #0 {main} thrown in /in/2W2At on line 14
Process exited with code 255.
Output for 5.6.0 - 5.6.28
12/31/2015object(DateTime)#1 (3) { ["date"]=> string(26) "2015-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(26) "2014-10-02 22:30:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Call to a member function diff() on string in /in/2W2At on line 14
Process exited with code 255.
Output for 5.4.30 - 5.4.45, 5.5.14 - 5.5.38
12/31/2015object(DateTime)#1 (3) { ["date"]=> string(26) "2015-12-31 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(26) "2014-10-02 22:30:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Call to a member function diff() on a non-object in /in/2W2At on line 14
Process exited with code 255.
Output for 5.3.0 - 5.4.29, 5.5.0 - 5.5.13
12/31/2015object(DateTime)#1 (3) { ["date"]=> string(19) "2015-12-31 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTime)#2 (3) { ["date"]=> string(19) "2014-10-02 22:30:45" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } Fatal error: Call to a member function diff() on a non-object in /in/2W2At on line 14
Process exited with code 255.
Output for 5.2.6 - 5.2.17
12/31/2015object(DateTime)#1 (0) { } object(DateTime)#2 (0) { } Notice: Undefined property: DateTime::$date in /in/2W2At on line 12 Notice: Undefined property: DateTime::$date in /in/2W2At on line 13 Fatal error: Call to a member function diff() on a non-object in /in/2W2At on line 14
Process exited with code 255.
Output for 5.2.0 - 5.2.5
12/31/2015object(DateTime)#1 (0) { } object(DateTime)#2 (0) { } Notice: Undefined property: DateTime::$date in /in/2W2At on line 12 Notice: Undefined property: DateTime::$date in /in/2W2At on line 13 Fatal error: Call to a member function diff() on a non-object in /in/2W2At on line 14
Process exited with code 255.
Output for 5.0.0 - 5.1.6
12/31/2015 Fatal error: Class 'DateTime' not found in /in/2W2At on line 8
Process exited with code 255.
Output for 4.3.2 - 4.4.9
12/31/2015 Fatal error: Cannot instantiate non-existent class: datetime in /in/2W2At on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1
12/31/2015 Fatal error: Cannot instantiate non-existent class: datetime in /in/2W2At on line 8