3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo file_get_contents('/tmp/test.php'); ?>
Output for 5.2.14 - 5.4.45, 5.5.32, 5.6.7, 5.6.19, 5.6.28, 7.0.0 - 7.0.1, 7.0.14 - 7.1.0
Warning: file_get_contents(/tmp/test.php): failed to open stream: No such file or directory in /in/eHHPa on line 2
Output for 5.5.24 - 5.5.31, 5.5.33 - 5.5.35, 5.6.8 - 5.6.18, 5.6.20 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.2 - 7.0.6
<?php namespace Zend\Stdlib;use DateTimeZone;class DateTime extends\DateTime{public function __construct($time='now',DateTimeZone $timezone=null){if(version_compare(PHP_VERSION,'5.3.7','>=')){return parent::__construct($time,$timezone);}if(!stristr($time,'last')&&!stristr($time,'first')){if($timezone){return parent::__construct($time,$timezone);}else{return parent::__construct($time);}}if($timezone){parent::__construct('now',$timezone);}else{parent::__construct('now');}$this->setTimestamp(strtotime($time,$this->getTimestamp()));return $this;}public function modify($modify){if(version_compare(PHP_VERSION,'5.3.7','>=')){return parent::modify($modify);}if(!stristr($modify,'last')&&!stristr($modify,'first')){return parent::modify($modify);}$parsedTimestamp=strtotime($modify,$this->getTimestamp());if($parsedTimestamp===false){return false;}$this->setTimestamp($parsedTimestamp);return $this;}}class classDateTimeTest{protected $revertTz=null;public function setup(){}public function teardown(){if($this->revertTz){date_default_timezone_set($this->revertTz);$this->revertTz=null;}}protected function setDefaultTz($tz){if(!$this->revertTz){$this->revertTz=date_default_timezone_get();}date_default_timezone_set($tz);}public function testBug62896and62561(){$this->setDefaultTz('GMT');$tz=new DateTimeZone('Europe/Berlin');$date=new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));$this->assertEquals('2012-08-21 22:00:00 GMT+0000 (offset 0)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, no timezone, after +0 days');$date->modify('+0 days');$this->assertEquals('2012-08-21 22:00:00 GMT+0000 (offset 0)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, no timezone, after +0 days');$date=new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));$date->setTimezone($tz);$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, with timezone');$date->modify('+0 days');$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, with timezone, after +0 days');$date=new DateTime('2012-08-22 00:00:00 CEST',$tz);$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from a string, with timezone');$date->modify('+0 days');$date=new DateTime('2012-08-22 00:00:00 CEST',$tz);$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from a string, with timezone, after +0 days');$this->setDefaultTz('Asia/Seoul');$tz=new DateTimeZone('Europe/Berlin');$date=new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));$this->assertEquals('2012-08-21 22:00:00 GMT+0000 (offset 0)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, no timezone, after +0 days');$date->modify('+0 days');$this->assertEquals('2012-08-21 22:00:00 GMT+0000 (offset 0)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, no timezone, after +0 days');$date=new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));$date->setTimezone($tz);$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, with timezone');$date->modify('+0 days');$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from timestamp, with timezone, after +0 days');$date=new DateTime('2012-08-22 00:00:00 CEST',$tz);$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from a string, with timezone');$date->modify('+0 days');$date=new DateTime('2012-08-22 00:00:00 CEST',$tz);$this->assertEquals('2012-08-22 00:00:00 CEST (offset 7200)',$date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")",'default tz is Amsterdam, date from a string, with timezone, after +0 days');}protected function assertEquals($a,$b,$message=null){if($a!=$b){throw new\Exception(($message?$message."\n":"")."\"$a\" != \"$b\"\n");}}}$testClass=new\ReflectionClass(__NAMESPACE__.'\classDateTimeTest');foreach($testClass->getMethods()as $method){if(substr($method->getShortName(),0,4)!=='test')continue;try{$test=new classDateTimeTest();$test->setup();$method->invoke($test);$test->teardown();}catch(\Exception $e){echo 'FAIL: '.$method->getShortName();$trace=$e->getTrace();echo ' | line '.$trace[0]['line']."\n";echo $e->getMessage()."\n";try{$test->teardown();}catch(\Exception $e){}continue;}echo 'PASS: '.$method->getShortName()."\n";}