3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Query { protected $table = ''; protected $querystring = ''; public function __construct($pdo = '') { $this->connection = $pdo; return $this; } public function query($query) { $this->querystring = $query; return $this->execute(); } public function execute() { $this->querystring = str_replace([':fields', ':where', ':orderby', ':limit'], ['*', '', '', ''], $this->querystring); return $this->connection->query($this->querystring); } public function safeVar($var) { if (is_int($var)) { return (int) $var; } elseif (is_string($var)) { return '"'.(string) $var.'"'; } elseif (is_array($var)) { return '"'.implode(', ', $var).'"'; } return $var; } public function where(...$rules) { if (!strpos($this->querystring, ':where')) { return false; } $where = ''; foreach ($rules as $rule) { if (!isset($rule['field']) || !isset($rule['way']) || !isset($rule['against'])) { if (!isset($rule[0]) || !isset($rule[1]) || !isset($rule[2])) { return false; } else { $where .= " AND `{$rule[0]}` {$rule[1]} {$rule[2]}"; } } else { $where .= " AND `{$rule['field']}` {$rule['way']} ".safeVar($rule['against']).""; } } $this->querystring = str_replace(':where', ' WHERE '.trim($where, ' AND '), $this->querystring); return $this; } public function orderby($field, $way = 'DESC') { if (!strpos($this->querystring, ':orderby')) { return false; } $way = strtoupper((string) $way); if (!in_array($way, ['DESC', 'ASC'])) { $way = 'DESC'; } $this->querystring = str_replace(':orderby', "ORDERBY `{$field}` {$way}", $this->querystring); return $this; } public function limit($from, $to) { if (!strpos($this->querystring, ':limit')) { return false; } $from = (int) $from; $to = (int) $to; $this->querystring = str_replace(':limit', "LIMIT {$from}, {$to}", $this->querystring); return $this; } public function __toString() { return $this->querystring; } } class Select extends Query { public function __construct(\PDO $pdo, $table) { parent::__construct($pdo); $this->table = $table; $this->querystring = "SELECT :fields FROM {$table}:where:orderby:limit;"; } public function get(...$fields = ['*']) { if (!strpos($this->querystring, ':fields')) { return false; } $this->querystring = str_replace(':fields', implode(', ', $fields), $this->querystring); return $this; } public function first() { if (!strpos($this->querystring, ':limit')) { return false; } $this->querystring = str_replace(':limit', 'LIMIT 0, 1', $this->querystring); return $this; } } class Update extends Query { public function __construct(\PDO $pdo, $table) { parent::__construct($pdo); $this->table = $table; $this->querystring = 'UPDATE :table SET :values:where:orderby:limit;'; } } class Delete extends Query { public function __construct(\PDO $pdo, $table) { parent::__construct($pdo); $this->table = $table; $this->querystring = 'DELETE FROM :table:where:orderby:limit;'; } } class Insert extends Query { public function __construct(\PDO $pdo, $table) { parent::__construct($pdo); $this->table = $table; $this->querystring = 'INSERT INTO :table:fields VALUES :values;'; } } $select = new Select('', 'test'); $update = new Update('', 'test'); $delete = new Delete('', 'test'); $insert = new Insert('', '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)
5.4.350.0060.03812.04
5.4.340.0120.05312.04
5.4.320.0070.06812.52
5.4.310.0080.05412.52
5.4.300.0140.10512.52
5.4.290.0160.06212.52
5.4.280.0090.04012.42
5.4.270.0050.04512.41
5.4.260.0130.05212.41
5.4.250.0050.04712.42
5.4.240.0060.03912.42
5.4.230.0110.03512.41
5.4.220.0020.04312.41
5.4.210.0100.04012.41
5.4.200.0110.05412.41
5.4.190.0050.05112.41
5.4.180.0090.03812.40
5.4.170.0080.03512.41
5.4.160.0160.06512.41
5.4.150.0110.09912.41
5.4.140.0060.04712.10
5.4.130.0110.05712.08
5.4.120.0160.08112.04
5.4.110.0120.05512.04
5.4.100.0140.05512.04
5.4.90.0150.04712.04
5.4.80.0130.07812.04
5.4.70.0110.04012.04
5.4.60.0150.05412.03
5.4.50.0090.04812.03
5.4.40.0070.03812.02
5.4.30.0050.03912.02
5.4.20.0070.03412.01
5.4.10.0100.03412.02
5.4.00.0080.04811.52
5.3.290.0090.05212.80
5.3.280.0090.04812.71
5.3.270.0110.04412.72
5.3.260.0060.04512.72
5.3.250.0070.04112.72
5.3.240.0080.03912.72
5.3.230.0130.05312.71
5.3.220.0060.04112.68
5.3.210.0080.03912.68
5.3.200.0060.03812.68
5.3.190.0080.04012.68
5.3.180.0100.05612.68
5.3.170.0030.04612.67
5.3.160.0080.03912.67
5.3.150.0100.04012.67
5.3.140.0050.04212.66
5.3.130.0090.04312.66
5.3.120.0060.04412.66
5.3.110.0100.03712.66
5.3.100.0040.04312.13
5.3.90.0080.04312.11
5.3.80.0200.08912.10
5.3.70.0140.05912.10
5.3.60.0120.03612.09
5.3.50.0070.04012.03
5.3.40.0100.04712.03
5.3.30.0110.04412.00
5.3.20.0100.04111.77
5.3.10.0110.05111.74
5.3.00.0060.04911.72
5.2.170.0150.0529.23
5.2.160.0100.0499.23
5.2.150.0060.0319.23
5.2.140.0070.0309.23
5.2.130.0060.0319.19
5.2.120.0080.0349.18
5.2.110.0030.0389.19
5.2.100.0090.0389.19
5.2.90.0060.0509.19
5.2.80.0050.0349.19
5.2.70.0080.0329.19
5.2.60.0090.0319.14
5.2.50.0130.0629.10
5.2.40.0210.0589.08
5.2.30.0210.0679.07
5.2.20.0130.0539.05
5.2.10.0130.0368.96
5.2.00.0060.0368.82
5.1.60.0050.0298.10
5.1.50.0030.0288.10
5.1.40.0040.0268.08
5.1.30.0060.0288.43
5.1.20.0040.0278.45
5.1.10.0070.0248.18
5.1.00.0070.0258.18
5.0.50.0060.0266.65
5.0.40.0070.0266.51
5.0.30.0050.0426.32
5.0.20.0150.0446.29
5.0.10.0050.0406.27
5.0.00.0050.0406.25
4.4.90.0060.0204.77
4.4.80.0040.0224.76
4.4.70.0030.0194.76
4.4.60.0140.0394.75
4.4.50.0010.0234.77
4.4.40.0020.0334.70
4.4.30.0060.0634.76
4.4.20.0070.0224.85
4.4.10.0050.0174.85
4.4.00.0050.0504.76
4.3.110.0060.0394.67
4.3.100.0060.0294.66
4.3.90.0030.0234.63
4.3.80.0050.0534.59
4.3.70.0000.0224.63
4.3.60.0030.0194.63
4.3.50.0030.0204.63
4.3.40.0020.0284.54
4.3.30.0130.0703.30
4.3.20.0040.0213.29
4.3.10.0050.0333.24
4.3.00.0000.03712.46

preferences:
147.52 ms | 1394 KiB | 7 Q