3v4l.org

run code in 300+ PHP versions simultaneously
<?php try { $db = DatabasePDOTest::getInstance(); var_dump($db->connectToDatabase('test')); } catch (Exception $ex) { var_dump($ex); } echo "end"; final class DatabasePDOTest extends PDO { const STANDARD_DB = 'standard'; const DBHOST = 'host'; const DBUSER = 'user'; const DBPASS = 'password'; const DBNAME = 'dbname'; private static $_instance = null; private $_persistent = false; private $_databases = array(); private $_databaseHost = null; private $_databaseUser = null; private $_databasePass = null; private $_database = null; private $_charset = 'utf8'; public function __construct($persistent = false, $pathAddition = null, $databaseIdentifier = null) { $this->_loadConfig($pathAddition); $this->_persistent = $persistent; if (! is_null($databaseIdentifier)) { $this->connectToDatabase($databaseIdentifier); } else { if (array_key_exists(self::STANDARD_DB, $this->_databases)) { $this->connectToDatabase($this->_databases[self::STANDARD_DB]); } else { throw new InvalidArgumentException('no database set and no standard found'); } } } public function connectToDatabase($name) { if (! array_key_exists($name, $this->_databases)) { throw new UnexpectedValueException('identifier "' . $name . '" for database does not exist!'); } $this->_databaseHost = $this->_databases[$name][self::DBHOST]; $this->_databaseUser = $this->_databases[$name][self::DBUSER]; $this->_databasePass = $this->_databases[$name][self::DBPASS]; $this->_database = $this->_databases[$name][self::DBNAME]; return $this->connect(); } public static function getInstance($persistent = true, $pathAddition = null, $databaseIdentifier = null) { if (self::$_instance === null) { self::$_instance = new DatabasePDOTest($persistent, $pathAddition, $databaseIdentifier); } return self::$_instance; } public function getOneResultFlat(PDOStatement $stmt) { $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $return = array(); array_walk_recursive($results, function ($a) use (&$return) { $return[] = $a; }); return $return; } public function getMultipleResultFlat(PDOStatement $stmt) { $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $returnArray = array(); foreach ($results as $value) { foreach ($value as $key => $var) { $returnArray[$key][] = $var; } } return $returnArray; } public function getResultArray($sql) { $stmt = $this->query($sql); return $stmt->fetchAll(PDO::FETCH_ASSOC); } private function connect() { parent::__construct(sprintf('mysql:host=%1$s;dbname=%2$s;charset=%3$s', $this->_databaseHost, $this->_database, $this->_charset), $this->_databaseUser, $this->_databasePass, array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => $this->_persistent )); return true; } private function _loadConfig($pathAddition = null) { $this->_databases = array( "test" => array( "host" => "localhost", "user" => "test", "password" => "test", "dbname" => "test" ), "standard" => "test" ); } }

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.0100.01318.52
8.3.50.0080.00921.02
8.3.40.0090.00618.96
8.3.30.0120.00318.83
8.3.20.0050.00318.69
8.3.10.0080.00021.64
8.3.00.0080.00017.93
8.2.180.0130.00725.92
8.2.170.0170.00318.96
8.2.160.0060.01022.96
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0090.00021.04
8.2.120.0040.00426.35
8.2.110.0060.00321.04
8.2.100.0090.00317.85
8.2.90.0030.00718.22
8.2.80.0030.00717.97
8.2.70.0040.00417.50
8.2.60.0040.00417.93
8.2.50.0000.00818.10
8.2.40.0030.00520.42
8.2.30.0000.00820.55
8.2.20.0000.00717.80
8.2.10.0000.00718.09
8.2.00.0000.00918.09
8.1.280.0110.00425.92
8.1.270.0030.00624.04
8.1.260.0080.00028.09
8.1.250.0040.00428.09
8.1.240.0100.00019.27
8.1.230.0120.00020.96
8.1.220.0060.00317.78
8.1.210.0000.00818.77
8.1.200.0000.00917.47
8.1.190.0000.00917.35
8.1.180.0000.00818.10
8.1.170.0040.00418.95
8.1.160.0040.00419.10
8.1.150.0030.00618.94
8.1.140.0050.00219.63
8.1.130.0050.00217.76
8.1.120.0040.00417.41
8.1.110.0000.00817.38
8.1.100.0000.00717.40
8.1.90.0040.00417.47
8.1.80.0040.00417.51
8.1.70.0040.00417.48
8.1.60.0050.00317.63
8.1.50.0030.00617.57
8.1.40.0000.00817.57
8.1.30.0040.00417.70
8.1.20.0030.00617.74
8.1.10.0060.00317.47
8.1.00.0040.00417.39
8.0.300.0040.00420.20
8.0.290.0000.00716.88
8.0.280.0040.00418.48
8.0.270.0020.00517.37
8.0.260.0030.00517.18
8.0.250.0040.00417.07
8.0.240.0080.00017.04
8.0.230.0030.00417.05
8.0.220.0030.00616.92
8.0.210.0030.00317.00
8.0.200.0050.00517.00
8.0.190.0000.00717.04
8.0.180.0090.00017.08
8.0.170.0040.00417.02
8.0.160.0000.00816.95
8.0.150.0000.00716.99
8.0.140.0050.00316.98
8.0.130.0030.00313.51
8.0.120.0040.00416.87
8.0.110.0000.00816.89
8.0.100.0050.00316.97
8.0.90.0070.00016.89
8.0.80.0070.01116.89
8.0.70.0040.00416.82
8.0.60.0030.00516.98
8.0.50.0040.00417.00
8.0.30.0110.01217.21
8.0.20.0120.01017.40
8.0.10.0040.00416.98
8.0.00.0140.00716.68
7.4.330.0050.00015.15
7.4.320.0050.00316.60
7.4.300.0000.00716.66
7.4.290.0040.00416.54
7.4.280.0040.00416.63
7.4.270.0000.00716.41
7.4.260.0040.00416.61
7.4.250.0000.00716.46
7.4.240.0000.00716.54
7.4.230.0000.00716.44
7.4.220.0090.00916.58
7.4.210.0100.01016.52
7.4.200.0050.00216.52
7.4.160.0150.00416.52
7.4.150.0200.00317.40
7.4.140.0120.01017.86
7.4.130.0150.02416.50
7.4.120.0130.00816.52
7.4.110.0030.01416.54
7.4.100.0140.00916.50
7.4.90.0120.00816.43
7.4.80.0100.01319.39
7.4.70.0120.00616.49
7.4.60.0120.00616.39
7.4.50.0060.00916.58
7.4.40.0130.01416.60
7.4.30.0100.00816.45
7.4.00.0140.00515.06
7.3.330.0030.00313.48
7.3.320.0030.00313.50
7.3.310.0040.00416.56
7.3.300.0000.00716.57
7.3.290.0100.01016.53
7.3.280.0040.01916.48
7.3.270.0120.00917.40
7.3.260.0210.00316.53
7.3.250.0090.01116.50
7.3.240.0060.01416.59
7.3.230.0120.00616.63
7.3.210.0070.01116.78
7.3.200.0080.01019.39
7.3.190.0230.00816.53
7.3.180.0220.00316.77
7.3.170.0120.01416.60
7.3.160.0100.00716.49
7.3.120.0050.01315.06
7.3.110.0050.01114.94
7.3.100.0050.01214.76
7.3.90.0040.01414.82
7.3.80.0050.01314.81
7.3.70.0050.00515.02
7.3.60.0060.00414.98
7.3.50.0070.00914.81
7.3.40.0040.00814.80
7.3.30.0060.01014.92
7.3.20.0080.00416.80
7.3.10.0080.00716.79
7.3.00.0060.00816.64
7.2.330.0120.00916.88
7.2.320.0130.01416.50
7.2.310.0070.01316.89
7.2.300.0170.01016.75
7.2.290.0090.00916.94
7.2.250.0050.01115.06
7.2.240.0080.01115.20
7.2.230.0060.00915.27
7.2.220.0050.01115.01
7.2.210.0090.00715.04
7.2.200.0050.01015.33
7.2.190.0100.00714.91
7.2.180.0050.00515.13
7.2.170.0060.00915.10
7.2.60.0040.01117.11
7.1.330.0070.00815.97
7.1.320.0050.00915.61
7.1.310.0050.00915.69
7.1.300.0070.00615.80
7.1.290.0050.00815.86
7.1.280.0090.00515.82
7.1.270.0050.00815.80
7.1.260.0070.00915.82
7.1.200.0080.00615.80
7.1.100.0040.00418.39
7.1.70.0000.00817.13
7.1.60.0090.01619.30
7.1.50.0040.00717.01
7.1.00.0030.07322.34
7.0.200.0000.01116.67
7.0.60.0130.09319.93
7.0.50.0300.07320.43
7.0.40.0370.06720.42
7.0.30.0400.05720.39
7.0.20.0500.05020.39
7.0.10.0500.05320.26
7.0.00.0130.06720.38
5.6.280.0130.06721.15
5.6.210.0030.08320.55
5.6.200.0130.08021.18
5.6.190.0270.07021.18
5.6.180.0300.06021.18
5.6.170.0370.06721.16
5.6.160.0100.08021.20
5.6.150.0330.07021.20
5.6.140.0100.06021.13
5.6.130.0430.06321.10
5.6.120.0100.06321.20
5.6.110.0230.05021.08
5.6.100.0270.05021.14
5.6.90.0230.07021.08
5.6.80.0270.05320.57
5.6.70.0130.06020.42
5.6.60.0170.06020.61
5.6.50.0130.06320.48
5.6.40.0130.05320.50
5.6.30.0170.05720.43
5.6.20.0230.06020.42
5.6.10.0070.06020.58
5.6.00.0170.05720.54
5.5.350.0200.04320.51
5.5.340.0200.05321.04
5.5.330.0470.05020.87
5.5.320.0230.07020.89
5.5.310.0370.07020.89
5.5.300.0200.05720.92
5.5.290.0430.06020.84
5.5.280.0170.05720.93
5.5.270.0130.06021.05
5.5.260.0370.07020.93
5.5.250.0470.04720.75
5.5.240.0130.06720.32
5.5.230.0230.05020.26
5.5.220.0130.06020.27
5.5.210.0200.05020.41
5.5.200.0230.05020.25
5.5.190.0170.05720.25
5.5.180.0100.06020.25
5.5.160.0100.06020.09
5.5.150.0230.04720.27
5.5.140.0230.04720.20
5.5.130.0170.05320.31
5.5.120.0100.06020.30
5.5.110.0070.06720.26
5.5.100.0130.05719.99
5.5.90.0170.04719.95
5.5.80.0170.05320.23
5.5.70.0270.04720.21
5.5.60.0130.05020.13
5.5.50.0230.04320.22
5.5.40.0130.05019.94
5.5.30.0170.05020.11
5.5.20.0270.06020.28
5.5.10.0170.06320.09
5.5.00.0200.05720.10

preferences:
39.51 ms | 401 KiB | 5 Q