3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class DateTimeFactory { const DATE_INTERVAL = 'PT20M'; // I personally prefer adding DateInterval public static function createDateTimeByInterval1(DateInterval $dateInterval) { // create DateTime, add Date and/or TimeZone in constructor if needed. $dateTime = new DateTime(); return $dateTime->add($dateInterval); } // Using a ISO 8601 String public static function createDateTimeByInterval2($intervalStr) { // create DateTime, add Date and/or TimeZone in constructor if needed. $dateTime = new DateTime(); return $dateTime->add(new DateInterval($intervalStr)); } } var_dump( DateTimeFactory::createDateTimeByInterval1(new DateInterval(DateTimeFactory::DATE_INTERVAL)), DateTimeFactory::createDateTimeByInterval2(DateTimeFactory::DATE_INTERVAL), );
Output for 5.3.0 - 5.4.24
Parse error: syntax error, unexpected ')' in /in/4G6OY on line 27
Process exited with code 255.