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 '$field' not in the required format (MM/DD/YYYY or YYYY-MM-DD)."); } } var_dump($date);
based on PrHid
Output for 7.0.0 - 7.3.0rc3
Notice: Undefined variable: field in /in/kQYlI on line 9 Fatal error: Uncaught Exception: Date field '' not in the required format (MM/DD/YYYY or YYYY-MM-DD). in /in/kQYlI:9 Stack trace: #0 {main} thrown in /in/kQYlI on line 9
Process exited with code 255.
Output for hhvm-3.15.4
Notice: Undefined variable: field in /in/kQYlI on line 9 Fatal error: Uncaught exception 'Exception' with message 'Date field '' not in the required format (MM/DD/YYYY or YYYY-MM-DD).' in /in/kQYlI:9 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Notice: Undefined variable: field in /in/kQYlI on line 9 Fatal error: Uncaught exception 'Exception' with message 'Date field '' not in the required format (MM/DD/YYYY or YYYY-MM-DD).' in /in/kQYlI:9 Stack trace: #0 {main} thrown in /in/kQYlI on line 9
Process exited with code 255.