3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input_date = '2015'; $date = \DateTime::createFromFormat('Y-m-d', $input_date); if (empty($date)) { $date = \DateTime::createFromFormat('m/d/Y', $input_date); if (empty($date)) { throw new \Exception("Date field asdf not in the required format (MM/DD/YYYY or YYYY-MM-DD)."); } } var_dump($date);
based on kQYlI
Output for 7.0.0 - 7.3.0rc3
Fatal error: Uncaught Exception: Date field asdf not in the required format (MM/DD/YYYY or YYYY-MM-DD). in /in/irLAm:9 Stack trace: #0 {main} thrown in /in/irLAm on line 9
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught exception 'Exception' with message 'Date field asdf not in the required format (MM/DD/YYYY or YYYY-MM-DD).' in /in/irLAm:9 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Fatal error: Uncaught exception 'Exception' with message 'Date field asdf not in the required format (MM/DD/YYYY or YYYY-MM-DD).' in /in/irLAm:9 Stack trace: #0 {main} thrown in /in/irLAm on line 9
Process exited with code 255.