3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Database { protected static $instance; protected $pdo; protected function __construct() { static $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; $this->pdo = new PDO('sqlite::memory:', null, null, $opt); } public static function instance() { if (null === self::$instance) { self::$instance = new self; } return self::$instance; } public function run($sql, $args = []) { if (!$args) { try { return $this->query($sql); } catch(\PDOException $e) { throw new \PDOQueryException($e->getMessage(), (int) $e->getCode(), $e); } } try { $stmt = $this->prepare($sql); } catch(\PDOException $e) { throw new \PDOPrepareException($e->getMessage(), (int) $e->getCode(), $e); } try { $stmt->execute($args); } catch(\PDOException $e) { throw new \PDOExecuteException($e->getMessage(), (int) $e->getCode(), $e); } return $stmt; } public function __call($method, $args) { if (is_callable([$this->pdo, $method])) { //php 5.6+ variadic optimization (aka splat operator) return $this->pdo->$method(...$args); //PHP <= 5.5 //return call_user_func_array(array($this->pdo, $method), $args); } throw new \BadMethodCallException(sprintf('Unknown method PDO::%s called!', $method)); } } interface DatabaseRunException {} class PDOPrepareException extends PDOException implements DatabaseRunException{} class PDOExecuteException extends PDOException implements DatabaseRunException{} class PDOQueryException extends PDOException implements DatabaseRunException{} //RunTime code if (PHP_VERSION_ID >= 70100) { try { $db = Database::instance(); var_dump($db->run('SELECT ?', ['foo', 'bar'])->fetch()); } catch(\PDOQueryException $e) { //Handle the query exception } catch(\PDOPrepareException $e) { //Handle the prepare exception } catch(\PDOExecuteException $e) { echo 'PDO::execute() failed'; //Handle the execute exception } } else { try { $db = Database::instance(); var_dump($db->run('SELECT ?', ['foo', 'bar'])->fetch()); } catch(\DatabaseRunException $e) { if ($e instanceof \PDOQueryException) { //Handle the query exception } elseif ($e instanceof \PDOPrepareException) { //Handle the prepare exception } elseif($e instanceof \PDOExecuteException) { echo 'PDO::execute() failed'; //Handle the execute exception } } }

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.4.140.0170.00518.54
8.4.130.0180.00418.82
8.4.120.0120.00823.16
8.4.110.0120.00819.85
8.4.100.0060.00418.75
8.4.90.0050.00621.46
8.4.80.0120.00421.41
8.4.70.0110.00919.75
8.4.60.0110.00921.30
8.4.50.0240.01019.08
8.4.40.0280.00819.06
8.4.30.0250.01119.06
8.4.20.0240.01119.88
8.4.10.0260.00819.35
8.3.270.0110.00917.35
8.3.260.0120.00617.56
8.3.250.0120.00419.51
8.3.240.0130.00817.20
8.3.230.0150.00517.47
8.3.220.0080.01021.66
8.3.210.0130.00717.34
8.3.200.0080.00117.80
8.3.190.0230.00817.77
8.3.180.0230.01018.38
8.3.170.0250.00817.52
8.3.160.0260.00717.52
8.3.150.0290.00517.33
8.3.140.0210.00717.31
8.3.130.0220.00418.43
8.3.120.0190.00718.53
8.3.110.0250.00619.14
8.3.100.0220.00420.81
8.3.90.0260.00622.11
8.3.80.0250.00217.29
8.3.70.0230.00917.50
8.3.60.0250.00618.31
8.3.50.0210.00917.42
8.3.40.0240.00419.07
8.3.30.0190.00719.07
8.3.20.0210.00420.03
8.3.10.0200.00719.77
8.3.00.0130.00522.31
8.2.290.0080.01217.86
8.2.280.0200.00818.59
8.2.270.0220.00817.65
8.2.260.0210.00817.82
8.2.250.0190.01317.51
8.2.240.0180.01217.73
8.2.230.0200.00919.90
8.2.220.0210.00927.37
8.2.210.0200.00422.16
8.2.200.0160.00917.48
8.2.190.0220.00917.37
8.2.180.0170.01017.69
8.2.170.0180.00520.71
8.2.160.0160.00620.66
8.2.150.0180.00621.35
8.2.140.0220.00421.57
8.2.130.0200.00622.28
8.2.120.0190.00720.08
8.2.110.0190.00619.98
8.2.100.0220.00418.61
8.2.90.0120.00419.56
8.2.80.0190.00819.88
8.2.70.0160.00818.39
8.2.60.0180.00718.46
8.2.50.0190.00618.37
8.2.40.0150.01018.45
8.2.30.0150.00218.54
8.2.20.0170.00718.61
8.2.10.0160.00918.98
8.2.00.0180.00919.28
8.1.330.0080.01217.00
8.1.320.0200.01017.05
8.1.310.0170.00817.24
8.1.300.0240.00718.21
8.1.290.0190.00923.77
8.1.280.0180.01021.42
8.1.270.0210.00520.81
8.1.260.0200.00522.27
8.1.250.0210.00423.20
8.1.240.0150.00820.60
8.1.230.0210.00720.07
8.1.220.0160.00618.26
8.1.210.0170.00619.06
8.1.200.0170.00718.26
8.1.190.0140.01118.91
8.1.180.0150.00918.20
8.1.170.0160.00618.72
8.1.160.0150.00818.82
8.1.150.0160.00718.96
8.1.140.0150.00618.87
8.1.130.0150.00819.48
8.1.120.0180.00618.31
8.1.110.0190.00618.17
8.1.100.0180.00518.21
8.1.90.0140.01018.12
8.1.80.0170.00618.06
8.1.70.0180.00518.23
8.1.60.0170.00718.31
8.1.50.0210.00518.28
8.1.40.0140.00918.39
8.1.30.0150.00918.46
8.1.20.0180.00918.42
8.1.10.0190.00618.38
8.1.00.0160.00618.32
8.0.300.0190.00519.26
8.0.290.0150.00817.64
8.0.280.0150.00718.59
8.0.270.0130.00717.95
8.0.260.0140.00919.25
8.0.250.0180.00417.75
8.0.240.0140.00617.89
8.0.230.0130.00717.74
8.0.220.0140.00417.70
8.0.210.0140.00817.72
8.0.200.0140.00717.73
8.0.190.0120.00717.70
8.0.180.0070.00617.70
8.0.170.0120.00117.69
8.0.160.0070.00517.67
8.0.150.0140.00517.62
8.0.140.0140.00717.61
8.0.130.0150.00715.88
8.0.120.0160.00617.54
8.0.110.0200.00517.58
8.0.100.0160.00617.44
8.0.90.0140.00517.56
8.0.80.0150.00817.64
8.0.70.0130.00717.56
8.0.60.0160.00417.56
8.0.50.0180.00517.49
8.0.30.0190.00717.98
8.0.20.0220.00817.72
8.0.10.0200.00617.64
8.0.00.0130.01317.62
7.4.330.0160.00516.42
7.4.320.0150.00717.13
7.4.300.0130.00617.27
7.4.290.0120.00617.23
7.4.280.0150.00717.36
7.4.270.0170.00717.20
7.4.260.0140.00817.26
7.4.250.0170.00517.09
7.4.240.0130.00317.14
7.4.230.0180.00317.28
7.4.220.0150.00617.11
7.4.210.0120.01017.20
7.4.200.0150.00517.22
7.4.190.0260.00917.27
7.4.180.0300.00517.22
7.4.160.0140.00817.29
7.4.150.0270.00718.50
7.4.140.0170.01017.44
7.4.130.0220.00717.21
7.4.120.0220.00717.11
7.4.110.0180.01017.34
7.4.100.0190.01217.41
7.4.90.0180.00717.12
7.4.80.0180.00818.30
7.4.70.0190.01017.19
7.4.60.0180.00817.25
7.4.50.0140.01117.28
7.4.40.0230.00317.24
7.4.30.0280.00616.97
7.4.20.0260.00717.07
7.4.10.0250.00817.13
7.4.00.0230.00716.47
7.3.330.0130.00515.65
7.3.320.0150.00515.70
7.3.310.0150.00517.15
7.3.300.0140.00717.03
7.3.290.0140.01317.13
7.3.280.0130.01117.06
7.3.270.0250.00816.79
7.3.260.0140.00717.20
7.3.250.0230.01017.02
7.3.240.0120.00917.14
7.3.230.0170.00817.10
7.3.220.0270.00816.93
7.3.210.0210.00917.07
7.3.200.0190.00717.14
7.3.190.0170.00917.24
7.3.180.0180.01017.04
7.3.170.0220.00817.15
7.3.160.0130.01217.06
7.3.150.0270.00717.05
7.3.140.0270.00817.06
7.3.130.0250.00816.95
7.3.120.0260.00617.11
7.3.110.0230.00417.08
7.3.100.0220.00716.96
7.3.90.0230.01117.28
7.3.80.0260.00817.00
7.3.70.0300.00517.02
7.3.60.0280.00617.11
7.3.50.0140.01015.95
7.3.40.0100.00915.96
7.3.30.0140.00715.95
7.3.20.0180.00916.56
7.3.10.0170.00916.49
7.3.00.0190.00916.56
7.2.340.0250.01016.87
7.2.330.0140.01117.25
7.2.320.0160.01017.11
7.2.310.0170.01117.21
7.2.300.0160.00917.19
7.2.290.0170.00817.19
7.2.280.0230.00817.01
7.2.270.0250.00817.09
7.2.260.0270.00716.93
7.2.250.0270.00717.09
7.2.240.0210.00917.01
7.2.230.0250.01016.91
7.2.220.0290.00517.00
7.2.210.0270.00717.15
7.2.200.0270.00617.16
7.2.190.0220.01217.04
7.2.180.0140.00916.15
7.2.170.0160.00816.16
7.2.160.0120.01116.22
7.2.150.0170.00716.69
7.2.140.0160.00816.89
7.2.130.0380.00516.84
7.2.120.0160.01016.78
7.2.110.0160.00816.80
7.2.100.0160.00716.88
7.2.90.0150.00716.90
7.2.80.0160.00516.84
7.2.70.0170.00516.92
7.2.60.0160.00916.86
7.2.50.0180.00316.70
7.2.40.0320.00916.82
7.2.30.0140.00816.90
7.2.20.0180.01016.79
7.2.10.0180.00716.67
7.2.00.0140.00916.94
7.1.330.0280.00417.82
7.1.320.0250.00817.81
7.1.310.0230.00917.98
7.1.300.0240.00717.73
7.1.290.0250.00717.62
7.1.280.0150.01115.55
7.1.270.0440.00615.61
7.1.260.0140.00815.57
7.1.250.0150.00815.47
7.1.240.0180.00615.64
7.1.230.0150.00715.64
7.1.220.0180.00815.55
7.1.210.0200.00715.59
7.1.200.0260.00815.58
7.1.190.0120.00915.50
7.1.180.0140.00615.68
7.1.170.0140.00715.61
7.1.160.0160.00615.61
7.1.150.0160.00815.53
7.1.140.0170.00815.67
7.1.130.0190.00815.56
7.1.120.0160.01015.53
7.1.110.0190.00415.60
7.1.100.0180.00815.51
7.1.90.0170.01115.60
7.1.80.0180.00615.59
7.1.70.0150.00915.51
7.1.60.0210.00915.52
7.1.50.0180.00915.63
7.1.40.0170.00415.63
7.1.30.0170.01015.59
7.1.20.0410.00915.63
7.1.10.0180.00615.80
7.1.00.0130.01015.53

preferences:
67.37 ms | 403 KiB | 5 Q