3v4l.org

run code in 300+ PHP versions simultaneously
<?php class InvalidFileFormatException extends Exception { // Redefine the exception so message isn't optional public function __construct($message, $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } // custom string representation of object public function __toString() { if ($code > 0) { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; } else { return __CLASS__ . ": {$this->message}\n"; } } } class FileIOException extends Exception { // Redefine the exception so message isn't optional public function __construct($message, $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } // custom string representation of object public function __toString() { return __CLASS__ . ": {$this->message}\n"; } } //============================================== // class //============================================== abstract class PDOWrapper { //============================================== // variables //============================================== private $exception = Null; private $username = Null; private $password = Null; private $dsn = Null; private $client = Null; private $pdoStatement = Null; //============================================== // constructor //============================================== final public function __construct() { $this->reset(); } //============================================== // overrides //============================================== abstract protected function getConfigFile(); //============================================== // main //============================================== final public function prepare($query) { if ($this->ready()) { $this->pdoStatement = $this->client->prepare($query); } return $this->checkError(); } final public function execute() { if ($this->ready() && $this->pdoStatement) { return $this->pdoStatement->execute(); } return $this->checkError(); } final public function fetch() { if ($this->ready() && $this->pdoStatement) { return $this->pdoStatement->fetch(); } return False; } final public function fetchAll() { if ($this->ready() && $this->pdoStatement) { return $this->pdoStatement->fetchAll(); } return False; } final public function query($query) { if ($this->ready()) { $this->pdoStatement = $this->client->query($query); } return $this->checkError(); } final public function ready() { return !$this->hasException(); } final public function reset() { $exception = Null; try { $this->loadConfigFile($this->getConfigFile()); //may throw error (see __get()) $this->client = new PDO($this->dsn, $this->username, $this->password); } catch (Exception $e) { $this->exception = $e; } } //============================================== // accessing //============================================== final public function hasException() { return isset($this->exception); } final public function getException() { return $this->exception; } final public function getRowCount() { if ($this->pdoStatement && !empty($this->pdoStatement->errorInfo()[2])) { return $this->pdoStatement->rowCount(); } return False; } final protected function setException($e) { $this->exception = $e; } //============================================== // utility //============================================== final private function checkError() { //pdoStatement->errorInfo() always returns array if ($this->pdoStatement == False) { $this->exception = new PDOException('Connection Error - Please Check Config File and Network'); return False; } if (!empty($this->pdoStatement->errorInfo()[2])) { $msg = $this->client->errorInfo()[2]; $errCode = $this->client->errorCode(); $this->exception = new PDOException($msg, $code = $errCode); return False; } return True; } final private function loadConfigFile($filepath) { $string = @file_get_contents($filepath); if ($string === False) { throw new FileIOException($filepath); } $json = @json_decode($string, true); if ($json === False || !$json['USERNAME'] || !$json['PASSWORD'] || !$json['DSN']) { throw new InvalidFileFormatException($filepath . ' : ' . json_last_error_msg(), $code = json_last_error()); } $this->username = $json['USERNAME']; $this->password = $json['PASSWORD']; $this->dsn = $json['DSN']; } } class MySqlDB extends PDOWrapper { //============================================== // overrides //============================================== final protected function getConfigFile() { return '~/.mysql/config.json'; } } class RedshiftDB extends PDOWrapper { //============================================== // overrides //============================================== final protected function getConfigFile() { return '~/.redshift/config.json'; } } $a = new RedshiftDB(); echo $a->hasError();

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.40.0130.00618.79
8.3.30.0070.00718.72
8.3.20.0050.00320.39
8.3.10.0000.00822.03
8.3.00.0000.00822.07
8.2.170.0150.00622.96
8.2.160.0070.00720.69
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0000.00820.91
8.2.120.0050.00326.35
8.2.110.0000.00919.46
8.2.100.0040.00818.05
8.2.90.0000.00819.18
8.2.80.0040.00417.97
8.2.70.0030.00717.63
8.2.60.0000.00818.16
8.2.50.0120.00018.09
8.2.40.0040.00422.13
8.2.30.0030.00519.57
8.2.20.0000.00817.82
8.2.10.0030.00518.33
8.2.00.0040.00418.08
8.1.270.0040.00422.12
8.1.260.0040.00428.09
8.1.250.0000.00728.09
8.1.240.0030.00722.06
8.1.230.0070.00317.77
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0040.00417.48
8.1.180.0000.00818.10
8.1.170.0030.00518.48
8.1.160.0000.00820.86
8.1.150.0050.00518.88
8.1.140.0030.00519.54
8.1.130.0000.00717.73
8.1.120.0000.00717.46
8.1.110.0070.00017.54
8.1.100.0070.00017.51
8.1.90.0000.00717.59
8.1.80.0030.00717.57
8.1.70.0040.00417.40
8.1.60.0030.00517.57
8.1.50.0030.00617.59
8.1.40.0000.00817.67
8.1.30.0040.00417.79
8.1.20.0030.00517.63
8.1.10.0040.00417.66
8.1.00.0050.00317.49
8.0.300.0080.00018.84
8.0.290.0040.00417.00
8.0.280.0030.00318.50
8.0.270.0040.00417.37
8.0.260.0000.00717.40
8.0.250.0000.00817.17
8.0.240.0030.00517.17
8.0.230.0040.00417.13
8.0.220.0000.01017.12
8.0.210.0000.00717.02
8.0.200.0000.00617.21
8.0.190.0000.00817.16
8.0.180.0030.00517.15
8.0.170.0060.00317.03
8.0.160.0020.00517.06
8.0.150.0000.00717.12
8.0.140.0070.00016.91
8.0.130.0000.00713.56
8.0.120.0040.00416.98
8.0.110.0070.00017.13
8.0.100.0070.00017.06
8.0.90.0040.00416.98
8.0.80.0100.01317.08
8.0.70.0000.00716.93
8.0.60.0000.00816.98
8.0.50.0040.00417.15
8.0.30.0060.01117.17
8.0.20.0120.00717.47
8.0.10.0050.00317.20
8.0.00.0090.01016.77
7.4.330.0020.00216.77
7.4.320.0070.00016.61
7.4.300.0070.00016.57
7.4.290.0050.00316.68
7.4.280.0000.00816.59
7.4.270.0070.00016.45
7.4.260.0040.00416.60
7.4.250.0050.00216.68
7.4.240.0050.00316.67
7.4.230.0000.00716.41
7.4.220.0110.00716.71
7.4.210.0080.00716.64
7.4.200.0030.00616.78
7.4.160.0070.00916.58
7.4.150.0070.01117.40
7.4.140.0160.00317.86
7.4.130.0130.00816.64
7.4.120.0100.00816.57
7.4.110.0090.00916.61
7.4.100.0110.00616.60
7.4.90.0060.01316.54
7.4.80.0070.01019.39
7.4.70.0150.00916.72
7.4.60.0180.00316.60
7.4.50.0070.00716.31
7.4.40.0100.00716.68
7.4.30.0110.01216.57
7.4.00.0080.00915.16
7.3.330.0040.00313.54
7.3.320.0050.00013.39
7.3.310.0000.00816.62
7.3.300.0000.00816.46
7.3.290.0030.00316.62
7.3.280.0070.00916.58
7.3.270.0130.01317.40
7.3.260.0090.00916.57
7.3.250.0070.01216.58
7.3.240.0130.00516.48
7.3.230.0100.00716.42
7.3.210.0100.00716.61
7.3.200.0150.00319.39
7.3.190.0100.00816.55
7.3.180.0100.00716.62
7.3.170.0090.00916.70
7.3.160.0090.00916.47
7.3.120.0070.01115.00
7.3.110.0060.01014.90
7.3.100.0100.00614.90
7.3.90.0040.00415.16
7.3.80.0060.00914.83
7.3.70.0030.00814.95
7.3.60.0070.01114.98
7.3.50.0100.00015.09
7.3.40.0030.01014.98
7.3.30.0060.00615.05
7.3.20.0040.01116.79
7.3.10.0070.00916.70
7.3.00.0090.00516.57
7.2.330.0090.00916.91
7.2.320.0070.01116.57
7.2.310.0110.00716.79
7.2.300.0060.01616.97
7.2.290.0130.00416.93
7.2.250.0070.01015.04
7.2.240.0060.01215.13
7.2.230.0110.00315.13
7.2.220.0030.00815.32
7.2.210.0030.01215.18
7.2.200.0000.01215.13
7.2.190.0070.00315.29
7.2.180.0090.00315.05
7.2.170.0040.01115.30
7.2.130.0030.00916.93
7.2.120.0000.01517.00
7.2.110.0100.00316.81
7.2.100.0060.00917.03
7.2.90.0030.01216.98
7.2.80.0090.00317.11
7.2.70.0070.00716.93
7.2.60.0060.00916.61
7.2.50.0040.01216.66
7.2.40.0100.00316.83
7.2.30.0030.01216.86
7.2.20.0040.00716.93
7.2.10.0000.01217.15
7.2.00.0050.00918.04
7.1.330.0080.00615.58
7.1.320.0070.00715.72
7.1.310.0000.00915.96
7.1.300.0000.01415.52
7.1.290.0030.00915.67
7.1.280.0090.00616.00
7.1.270.0040.00415.82
7.1.260.0100.00316.00
7.1.250.0000.01015.71
7.1.200.0120.00315.84
7.1.100.0060.00618.36
7.1.70.0030.00917.26
7.1.60.0000.01719.40
7.1.50.0110.01116.86
7.1.00.0100.06722.36
7.0.200.0290.00715.10
7.0.100.0230.08020.03
7.0.90.0330.06319.93
7.0.80.0230.06720.20
7.0.70.0130.04719.97
7.0.60.0130.05319.95
7.0.50.0100.07320.35
7.0.40.0030.07720.05
7.0.30.0100.07720.00
7.0.20.0070.08320.09
7.0.10.0100.04719.95
7.0.00.0070.08320.05
5.6.280.0030.03321.13
5.6.250.0030.08720.61
5.6.240.0100.07720.80
5.6.230.0130.07020.68
5.6.220.0030.08720.66
5.6.210.0070.08020.70
5.6.200.0130.07321.22
5.6.190.0100.07321.10
5.6.180.0130.04721.15
5.6.170.0170.06321.13
5.6.160.0030.07321.02
5.6.150.0030.08321.14
5.6.140.0030.08321.11
5.6.130.0170.04721.02
5.6.120.0000.05321.09
5.6.110.0070.07021.12
5.6.100.0000.04721.00
5.6.90.0030.04721.15
5.6.80.0000.04320.50
5.6.70.0030.03720.55
5.6.60.0100.03320.46
5.6.50.0070.04320.48
5.6.40.0130.03020.45
5.6.30.0000.06720.53
5.6.20.0030.06320.35
5.6.10.0030.04020.59
5.6.00.0070.03720.44
5.5.380.0070.08020.59
5.5.370.0030.05320.44
5.5.360.0170.07320.61
5.5.350.0070.08720.51
5.5.340.0130.07021.00
5.5.330.0030.07320.99
5.5.320.0070.07720.70
5.5.310.0100.08320.82
5.5.300.0070.07720.89
5.5.290.0130.04320.89
5.5.280.0100.07720.70
5.5.270.0270.03020.81
5.5.260.0070.04020.69
5.5.250.0030.05320.71
5.5.240.0000.04320.29
5.5.230.0030.07020.31
5.5.220.0000.04320.32
5.5.210.0030.04020.36
5.5.200.0030.04320.35
5.5.190.0070.05320.30
5.5.180.0030.04320.21
5.5.160.0000.04320.22
5.5.150.0030.04020.24
5.5.140.0070.04320.24
5.5.130.0070.03720.31
5.5.120.0000.04320.24
5.5.110.0070.03720.33
5.5.100.0030.05320.15
5.5.90.0130.07020.18
5.5.80.0130.04020.01
5.5.70.0100.04720.23
5.5.60.0030.03720.22
5.5.50.0000.07720.03
5.5.40.0070.04720.23
5.5.30.0070.04320.17
5.5.20.0100.03320.22
5.5.10.0100.06020.18
5.5.00.0130.03320.13

preferences:
43.74 ms | 400 KiB | 5 Q