3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class MyDateTime extends DateTime { public static function createFromFormat($format, $time, $timezone = null) { $version = explode('.', phpversion()); if(!$timezone) $timezone = new DateTimeZone(date_default_timezone_get()); if(((int)$version[0] >= 5 && (int)$version[1] >= 2 && (int)$version[2] > 17)){ return parent::createFromFormat($format, $time, $timezone); } return new DateTime(date($format, strtotime($time)), $timezone); } } $dateTime = MyDateTime::createFromFormat('d m, Y', '04 25, 2014'); var_dump($dateTime); var_dump($dateTime->format('Y-m-d'));

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for Typed properties v2
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (01 01, 1970) at position 0 (0): Unexpected character in /in/DdnDP:11 Stack trace: #0 /in/DdnDP(11): DateTime->__construct('01 01, 1970', Object(DateTimeZone)) #1 /in/DdnDP(15): MyDateTime::createFromFormat('d m, Y', '04 25, 2014') #2 {main} thrown in /in/DdnDP on line 11
Output for Array change keys
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (01 01, 1970) at position 0 (0): Unexpected character in /in/DdnDP:11 Stack trace: #0 /in/DdnDP(11): DateTime->__construct('01 01, 1970', Object(DateTimeZone)) #1 /in/DdnDP(15): MyDateTime::createFromFormat('d m, Y', '04 25, 2014') #2 {main} thrown in /in/DdnDP on line 11
Output for Lexical anon
Strict Standards: Declaration of MyDateTime::createFromFormat() should be compatible with DateTime::createFromFormat($format, $time, DateTimeZone $object = NULL) in /in/DdnDP on line 13 Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (01 01, 1970) at position 0 (0): Unexpected character' in /in/DdnDP:11 Stack trace: #0 /in/DdnDP(11): DateTime->__construct('01 01, 1970', Object(DateTimeZone)) #1 /in/DdnDP(15): MyDateTime::createFromFormat('d m, Y', '04 25, 2014') #2 {main} thrown in /in/DdnDP on line 11

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page