3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Zend\Stdlib; if(version_compare(PHP_VERSION,'5.3.0','<')) exit; use DateTimeZone; class DateTime extends \DateTime { public function __construct($time = 'now', DateTimeZone $timezone = null) { // Workaround not required for PHP 5.3.7 or newer if (version_compare(PHP_VERSION, '5.3.7', '>=')) { return parent::__construct($time, $timezone); } // Check if using relative constructs if (!stristr($time, 'last') && !stristr($time, 'first')) { if ($timezone) { return parent::__construct($time, $timezone); } else { return parent::__construct($time); } } // Use current time with constructor to prevent setting 'first_last_day_of' flag. // The branching is required for older PHP to prevent DateTime exception of null timezone. if ($timezone) { parent::__construct('now', $timezone); } else { parent::__construct('now'); } // Set the timestamp by relying on strtotime and avoiding setting the // internal 'first_last_day_of' flag of DateTime object. $this->setTimestamp( strtotime($time, $this->getTimestamp()) ); return $this; } public function modify($modify) { // Workaround not required for PHP 5.3.7 or newer if (version_compare(PHP_VERSION, '5.3.7', '>=')) { return parent::modify($modify); } // Check if using relative constructs if (!stristr($modify, 'last') && !stristr($modify, 'first')) { return parent::modify($modify); } // Set the timestamp by relying on strtotime and avoiding setting the // internal 'first_last_day_of' flag of DateTime object. $parsedTimestamp = strtotime($modify, $this->getTimestamp()); if ($parsedTimestamp === false) { return false; // something went wrong parsing the date } $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); } } /** * PHP Bug #62896 Unixtimestamp may take on local times DST flag (this test will only be valid during CEST) * PHP Bug #62561 DateTime add 'P1D' adds 25 hours * * @link https://bugs.php.net/bug.php?id=62896 * @link https://bugs.php.net/bug.php?id=62561 */ public function testBug62896and62561() { $this->setDefaultTz('Europe/Amsterdam'); $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 : "" ) . "\"$a\" != \"$b\"\n"); } } } // run tests $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().': '.$e->getMessage()."\n"; try{ $test->teardown(); }catch(\Exception $e){} continue; } echo 'PASS: '.$method->getShortName()."\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0090.01218.55
8.3.50.0090.00922.03
8.3.40.0060.00919.06
8.3.30.0040.01219.14
8.3.20.0090.00018.88
8.3.10.0000.00821.17
8.3.00.0000.00821.76
8.2.180.0090.00616.75
8.2.170.0140.00422.96
8.2.160.0060.00920.64
8.2.150.0050.00324.18
8.2.140.0090.00624.66
8.2.130.0070.00026.16
8.2.120.0040.00420.78
8.2.110.0060.00320.79
8.2.100.0030.00818.16
8.2.90.0040.00419.32
8.2.80.0060.00317.97
8.2.70.0000.00817.88
8.2.60.0040.00418.18
8.2.50.0120.00318.07
8.2.40.0040.00418.47
8.2.30.0050.00321.39
8.2.20.0000.00818.02
8.2.10.0000.00817.97
8.2.00.0030.00618.09
8.1.280.0180.00425.92
8.1.270.0040.00423.99
8.1.260.0030.00526.35
8.1.250.0000.00828.09
8.1.240.0070.00322.59
8.1.230.0120.00021.12
8.1.220.0060.00318.77
8.1.210.0000.00919.01
8.1.200.0070.00317.73
8.1.190.0050.00317.89
8.1.180.0000.00818.10
8.1.170.0040.00418.88
8.1.160.0040.00419.17
8.1.150.0040.00418.96
8.1.140.0040.00417.88
8.1.130.0070.00018.02
8.1.120.0040.00417.84
8.1.110.0040.00417.77
8.1.100.0040.00417.72
8.1.90.0000.00817.85
8.1.80.0050.00317.72
8.1.70.0000.00717.82
8.1.60.0030.00617.94
8.1.50.0000.00817.76
8.1.40.0050.00317.82
8.1.30.0040.00417.95
8.1.20.0030.00517.99
8.1.10.0000.00817.89
8.1.00.0030.00617.83
8.0.300.0040.00420.21
8.0.290.0030.00617.30
8.0.280.0000.00718.70
8.0.270.0070.00017.49
8.0.260.0070.00017.10
8.0.250.0050.00217.26
8.0.240.0030.00617.25
8.0.230.0000.00717.31
8.0.220.0040.00417.28
8.0.210.0050.00317.26
8.0.200.0000.00617.33
8.0.190.0040.00417.26
8.0.180.0040.00417.30
8.0.170.0040.00417.34
8.0.160.0000.00817.23
8.0.150.0000.00717.27
8.0.140.0080.00017.17
8.0.130.0000.00613.73
8.0.120.0060.00317.25
8.0.110.0000.00817.09
8.0.100.0070.00017.13
8.0.90.0080.00017.11
8.0.80.0040.01117.29
8.0.70.0000.00717.24
8.0.60.0040.00417.32
8.0.50.0000.00817.28
8.0.30.0190.00617.28
8.0.20.0030.01517.40
8.0.10.0040.00417.49
8.0.00.0080.00917.13
7.4.330.0000.00515.08
7.4.320.0030.00316.91
7.4.300.0030.00316.80
7.4.290.0000.00816.76
7.4.280.0000.00716.81
7.4.270.0080.00016.79
7.4.260.0000.00713.52
7.4.250.0000.00816.87
7.4.240.0030.00316.83
7.4.230.0050.00216.81
7.4.220.0090.01116.62
7.4.210.0090.00916.88
7.4.200.0070.00016.93
7.4.190.0040.00416.84
7.4.160.0140.01016.70
7.4.150.0090.00917.40
7.4.140.0100.00717.86
7.4.130.0100.01116.81
7.4.120.0060.01216.80
7.4.110.0120.00617.01
7.4.100.0120.00916.95
7.4.90.0090.00917.02
7.4.80.0110.00619.39
7.4.70.0060.01216.82
7.4.60.0070.01016.96
7.4.50.0080.00016.89
7.4.40.0060.00822.77
7.4.30.0100.00716.96
7.4.00.0070.01015.30
7.3.330.0000.00513.66
7.3.320.0000.00613.66
7.3.310.0030.00616.52
7.3.300.0000.00716.47
7.3.290.0060.01216.69
7.3.280.0070.01116.63
7.3.270.0090.00917.40
7.3.260.0090.01518.24
7.3.250.0050.01616.78
7.3.240.0090.00816.71
7.3.230.0070.01116.87
7.3.210.0110.00816.77
7.3.200.0110.00719.39
7.3.190.0160.00616.92
7.3.180.0100.00717.00
7.3.170.0090.00916.91
7.3.160.0000.01716.72
7.3.120.0040.00415.00
7.2.330.0090.00916.98
7.2.320.0060.01016.95
7.2.310.0060.01216.87
7.2.300.0060.01416.98
7.2.290.0110.00617.02
7.2.00.0000.01319.87
7.1.100.0030.01418.38
7.1.70.0000.01117.44
7.1.60.0040.01219.08
7.1.50.0080.00816.94
7.1.00.0070.06022.54
7.0.200.0040.00416.96
7.0.140.0000.07722.18
7.0.100.0100.08320.17
7.0.90.0200.08019.99
7.0.80.0200.08020.04
7.0.70.0170.08020.04
7.0.60.0200.06320.00
7.0.50.0100.08720.44
7.0.40.0030.08720.13
7.0.30.0070.08720.05
7.0.20.0000.07720.12
7.0.10.0130.08020.04
7.0.00.0070.08020.03
5.6.280.0000.07320.88
5.6.250.0030.08320.63
5.6.240.0070.08720.79
5.6.230.0030.09320.70
5.6.220.0070.08020.66
5.6.210.0200.06320.63
5.6.200.0170.07321.01
5.6.190.0070.08721.11
5.6.180.0000.09021.10
5.6.170.0100.08021.16
5.6.160.0100.07321.12
5.6.150.0200.04321.18
5.6.140.0100.07721.10
5.6.130.0130.08020.99
5.6.120.0030.08021.11
5.6.110.0100.08321.12
5.6.100.0170.05021.16
5.6.90.0030.09021.18
5.6.80.0130.06320.62
5.6.70.0030.08320.48
5.6.60.0030.08320.52
5.6.50.0070.05320.45
5.6.40.0070.03720.46
5.6.30.0000.04320.50
5.6.20.0130.04320.59
5.6.10.0100.05720.48
5.6.00.0000.07320.46
5.5.380.0130.07320.42
5.5.370.0130.08020.41
5.5.360.0130.08320.45
5.5.350.0070.08020.52
5.5.340.0030.08320.83
5.5.330.0100.07320.80
5.5.320.0070.08320.96
5.5.310.0100.08320.71
5.5.300.0030.08720.91
5.5.290.0100.08320.99
5.5.280.0100.08020.99
5.5.270.0100.08320.83
5.5.260.0130.07020.91
5.5.250.0130.07320.61
5.5.240.0200.08020.36
5.5.230.0130.08020.33
5.5.220.0030.06320.17
5.5.210.0070.04720.34
5.5.200.0070.04320.30
5.5.190.0100.03320.05
5.5.180.0030.04720.29
5.5.160.0030.04020.25
5.5.150.0130.03720.20
5.5.140.0070.03720.19
5.5.130.0130.06720.31
5.5.120.0030.05320.24
5.5.110.0100.04020.24
5.5.100.0070.04020.14
5.5.90.0130.06720.04
5.5.80.0030.04020.17
5.5.70.0070.05320.12
5.5.60.0130.03720.03
5.5.50.0070.03720.12
5.5.40.0100.06320.12
5.5.30.0030.04320.17
5.5.20.0130.03320.15
5.5.10.0030.05020.02
5.5.00.0000.04720.20
5.4.450.0070.05719.56
5.4.440.0200.04319.26
5.4.430.0070.08019.46
5.4.420.0070.08319.41
5.4.410.0070.07319.41
5.4.400.0270.05718.95
5.4.390.0100.08319.23
5.4.380.0030.08019.03
5.4.370.0130.04318.89
5.4.360.0170.03318.95
5.4.350.0030.04019.23
5.4.340.0100.03719.10
5.4.320.0030.05719.03
5.4.310.0030.04019.14
5.4.300.0030.04719.04
5.4.290.0100.04319.04
5.4.280.0030.04018.87
5.4.270.0130.04319.03
5.4.260.0030.04318.91
5.4.250.0030.04319.23
5.4.240.0100.03319.04
5.4.230.0100.03719.04
5.4.220.0030.04319.06
5.4.210.0070.03319.20
5.4.200.0000.04318.95
5.4.190.0070.03319.03
5.4.180.0030.04019.04
5.4.170.0030.04719.25
5.4.160.0030.06319.16
5.4.150.0030.03719.04
5.4.140.0000.04316.25
5.4.130.0030.03716.50
5.4.120.0030.03716.24
5.4.110.0000.03716.40
5.4.100.0030.04016.33
5.4.90.0030.03316.49
5.4.80.0070.03016.37
5.4.70.0030.03316.38
5.4.60.0070.05716.61
5.4.50.0070.03316.30
5.4.40.0100.05716.44
5.4.30.0030.03016.45
5.4.20.0100.06316.41
5.4.10.0100.06716.45
5.4.00.0070.03715.96
5.3.290.0100.03014.87
5.3.280.0030.04014.71
5.3.270.0000.04014.61
5.3.260.0070.03714.73
5.3.250.0070.04314.66
5.3.240.0030.03314.77
5.3.230.0070.03714.63
5.3.220.0070.03314.65
5.3.210.0070.03714.70
5.3.200.0070.03314.67
5.3.190.0030.03314.57
5.3.180.0100.03014.64
5.3.170.0100.03014.67
5.3.160.0030.03714.75
5.3.150.0070.02714.76
5.3.140.0070.03014.70
5.3.130.0030.06014.60
5.3.120.0030.04014.64
5.3.110.0070.08014.74
5.3.100.0130.07014.09
5.3.90.0100.06714.04
5.3.80.0070.07714.09
5.3.70.0170.05714.06
5.3.60.0030.06714.18
5.3.50.0030.06314.11
5.3.40.0100.07314.12
5.3.30.0100.07014.01
5.3.20.0000.07013.86
5.3.10.0100.07013.61
5.3.00.0000.08013.83

preferences:
46.65 ms | 400 KiB | 5 Q