3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyDateTime extends DateTime { public static function createFromFormat($dformat, $dvalue) { $schedule = $dvalue; $schedule_format = str_replace(array('Y','m','d', 'H', 'i','a'),array('%Y','%m','%d', '%I', '%M', '%p' ) ,$dformat); // %Y, %m and %d correspond to date()'s Y m and d. // %I corresponds to H, %M to i and %p to a $ugly = strptime($schedule, $schedule_format); $ymd = sprintf( // This is a format string that takes six total decimal // arguments, then left-pads them with zeros to either // 4 or 2 characters, as needed '%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, // This will be "111", so we need to add 1900. $ugly['tm_mon'] + 1, // This will be the month minus one, so we add one. $ugly['tm_mday'], $ugly['tm_hour'], $ugly['tm_min'], $ugly['tm_sec'] ); $new_schedule = new MyDateTime($ymd); return $new_schedule; } public function getTimestamp() { return method_exists('DateTime', 'getTimestamp') ? parent::getTimestamp() : $this->format('U'); } } $dateTime = MyDateTime::createFromFormat('d/m/Y', '13/06/2013'); var_dump($dateTime); var_dump($dateTime->format('Y-m-d')); var_dump($dateTime->getTimestamp()); ?>
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) must be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false in /in/EIbBH on line 3
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) must be compatible with DateTime::createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) in /in/EIbBH on line 3
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL) in /in/EIbBH on line 3 object(MyDateTime)#1 (3) { ["date"]=> string(26) "2013-06-13 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "2013-06-13" int(1371074400)
Output for 7.3.32 - 7.3.33
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL) in /in/EIbBH on line 29 object(MyDateTime)#1 (3) { ["date"]=> string(26) "2013-06-13 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } string(10) "2013-06-13" int(1371081600)
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, ?DateTimeZone $object = NULL) in /in/EIbBH on line 29 object(MyDateTime)#1 (3) { ["date"]=> string(26) "2013-06-13 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "2013-06-13" int(1371074400)
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33
Warning: Declaration of MyDateTime::createFromFormat($dformat, $dvalue) should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/EIbBH on line 29 object(MyDateTime)#1 (3) { ["date"]=> string(26) "2013-06-13 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "2013-06-13" int(1371074400)
Output for 5.4.30 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/EIbBH on line 29 object(MyDateTime)#1 (3) { ["date"]=> string(26) "2013-06-13 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "2013-06-13" int(1371074400)
Output for 5.4.0 - 5.4.29
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with DateTime::createFromFormat($format, $time, $object = NULL) in /in/EIbBH on line 29 object(MyDateTime)#1 (3) { ["date"]=> string(19) "2013-06-13 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "2013-06-13" int(1371074400)
Output for 5.3.0 - 5.3.29
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with that of DateTime::createFromFormat() in /in/EIbBH on line 29 object(MyDateTime)#1 (3) { ["date"]=> string(19) "2013-06-13 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "2013-06-13" int(1371074400)
Output for 5.2.0 - 5.2.17
object(MyDateTime)#1 (0) { } string(10) "2013-06-13" string(10) "1371074400"
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/EIbBH on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/EIbBH on line 3
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_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/EIbBH on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/EIbBH on line 3
Process exited with code 255.

preferences:
244.76 ms | 401 KiB | 354 Q