3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Query { private $select; private $from; private $where = []; /** * Defines the column list (SELECT {$columns}) * * @param string $columns * @return this */ public function select($columns) { $this->select = $columns; return $this; } /** * Defines the table to select from (SELECT * FROM {$table}) * * @param string $table * @return this */ public function from($table) { $this->from = $table; return $this; } /** * List of conditions to AND (key = column, value = value) * e.g. $query->where(['name' => 'bob']) * * @param mixed[string] $conditions * @return $this */ public function where(array $conditions) { $this->where = $conditions; return $this; } /** * Adds an AND condition * * @param string $column * @param mixed $value * @return this */ public function where_and($column, $value) { $this->where[$column] = $value; return $this; } /** * Builds and executes the query, returning a PDOStatement * * @return PDOStatement */ public function execute() { $query = sprintf( 'SELECT %s FROM %s', $this->select, $this->from ); $placeholders = array(); if (!empty($this->where)) { $query .= ' WHERE '; $index = 0; foreach ($this->where as $column => $value) { if ($index > 0) { $query .= ' AND '; } $query .= sprintf('`%s`', $column); if ($value === null) { $query .= ' IS NULL'; } else { $placeholder = sprintf(':placeholder_%d', $index); $query .= ' = ' . $placeholder; $placeholders[$placeholder] = $value; } $index++; } } // $pdo = new PDO($dsn, $user, $pass, $opt); // $stmt = $pdo->prepare($query); // $stmt->execute($placeholders); // return $stmt; echo $query . "\n\n"; print_r($placeholders); } } class MyClass { public function getData($name, $club) { $query = new Query(); $query->select('name') ->from('users') ->where(['quote' => '1']); $this->getQueryPart($query); $result = $query->execute(); // return $result->fetchAll(PDO::FETCH_ASSOC); } protected function getQueryPart($query) { $query->where_and('email', 'email@foobar.com') ->where_and('status', 1); } } $my_class = new MyClass(); $data = $my_class->getData('name', 'club'); // print_r($data);

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.0140.00817.71
8.4.130.0110.00820.57
8.4.120.0110.00520.65
8.4.110.0130.00722.31
8.4.100.0110.01017.87
8.4.90.0140.00718.73
8.4.80.0080.00619.38
8.4.70.0060.00317.69
8.4.60.0060.01420.52
8.4.50.0130.00724.22
8.4.40.0150.00619.20
8.4.30.0060.00319.62
8.4.20.0180.00417.47
8.4.10.0060.00319.67
8.3.270.0120.00916.39
8.3.260.0090.00716.48
8.3.250.0120.00619.07
8.3.240.0070.00916.82
8.3.230.0080.00116.86
8.3.220.0140.00516.99
8.3.210.0110.00616.69
8.3.200.0030.00616.58
8.3.190.0100.00818.87
8.3.180.0140.00716.79
8.3.170.0110.00317.39
8.3.160.0070.01118.45
8.3.150.0100.01017.32
8.3.140.0040.00420.85
8.3.130.0070.00316.71
8.3.120.0100.00018.93
8.3.110.0040.00420.94
8.3.100.0060.00324.06
8.3.90.0080.00026.77
8.3.80.0030.00616.65
8.3.70.0130.00318.16
8.3.60.0140.00716.50
8.3.50.0110.00517.45
8.3.40.0150.00018.97
8.3.30.0110.00418.79
8.3.20.0070.00020.16
8.3.10.0050.00322.04
8.3.00.0040.00423.43
8.2.290.0140.00520.73
8.2.280.0070.00418.63
8.2.270.0100.01016.98
8.2.260.0040.00416.96
8.2.250.0040.00416.50
8.2.240.0060.00317.08
8.2.230.0040.00422.58
8.2.220.0060.00337.54
8.2.210.0110.00426.77
8.2.200.0000.00916.50
8.2.190.0080.00818.16
8.2.180.0120.00316.50
8.2.170.0120.00322.96
8.2.160.0130.00720.19
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0080.00019.30
8.2.120.0040.00426.35
8.2.110.0040.00819.34
8.2.100.0100.00317.96
8.2.90.0070.00419.60
8.2.80.0000.00818.85
8.2.70.0050.00317.50
8.2.60.0000.00917.50
8.2.50.0040.00417.61
8.2.40.0060.00319.95
8.2.30.0070.00018.05
8.2.20.0000.00818.13
8.2.10.0030.00518.02
8.2.00.0060.00318.16
8.1.330.0100.01122.13
8.1.320.0110.00918.29
8.1.310.0000.01118.62
8.1.300.0090.00017.80
8.1.290.0040.00418.88
8.1.280.0100.01325.92
8.1.270.0030.00620.78
8.1.260.0080.00026.35
8.1.250.0060.00328.09
8.1.240.0070.00319.26
8.1.230.0080.00321.04
8.1.220.0050.00317.76
8.1.210.0000.00918.77
8.1.200.0030.00517.25
8.1.190.0000.00917.23
8.1.180.0030.00618.10
8.1.170.0040.00418.46
8.1.160.0000.00718.97
8.1.150.0040.00420.04
8.1.140.0020.00519.46
8.1.130.0000.01018.86
8.1.120.0040.00417.32
8.1.110.0080.00017.41
8.1.100.0050.00217.36
8.1.90.0070.00017.46
8.1.80.0000.00817.45
8.1.70.0030.00617.53
8.1.60.0030.00617.51
8.1.50.0060.00317.53
8.1.40.0000.00817.59
8.1.30.0000.00717.66
8.1.20.0050.00317.73
8.1.10.0040.00417.54
8.1.00.0040.00417.38
8.0.300.0040.00418.77
8.0.290.0060.00316.63
8.0.280.0000.00818.47
8.0.270.0070.00017.29
8.0.260.0090.00020.23
8.0.250.0080.00016.88
8.0.240.0030.00316.87
8.0.230.0000.00816.97
8.0.220.0050.00216.92
8.0.210.0000.00716.82
8.0.200.0000.00617.01
8.0.190.0040.00416.96
8.0.180.0040.00416.96
8.0.170.0040.00416.98
8.0.160.0050.00216.93
8.0.150.0000.00716.94
8.0.140.0000.01016.93
8.0.130.0000.00613.39
8.0.120.0020.00516.79
8.0.110.0040.00416.93
8.0.100.0040.00416.90
8.0.90.0030.00516.96
8.0.80.0060.00916.85
8.0.70.0040.00416.80
8.0.60.0020.00516.92
8.0.50.0040.00416.77
8.0.30.0050.01217.09
8.0.20.0150.00717.40
8.0.10.0040.00417.07
8.0.00.0110.00616.75
7.4.330.0000.00415.55
7.4.320.0000.00716.54
7.4.300.0000.00816.50
7.4.290.0000.00716.67
7.4.280.0000.00716.50
7.4.270.0030.00516.59
7.4.260.0030.00516.60
7.4.250.0000.00816.57
7.4.240.0050.00216.56
7.4.230.0000.00716.70
7.4.220.0110.00816.52
7.4.210.0090.00916.60
7.4.200.0070.00016.34
7.4.160.0110.00616.61
7.4.150.0060.01217.40
7.4.140.0070.01317.86
7.4.130.0090.01416.65
7.4.120.0110.00716.60
7.4.110.0140.00716.46
7.4.100.0090.00916.52
7.4.90.0140.00316.54
7.4.80.0100.00719.39
7.4.70.0130.00316.63
7.4.60.0100.00716.41
7.4.50.0110.00316.32
7.4.40.0270.03016.48
7.4.30.0000.01616.65
7.4.00.0000.01414.68
7.3.330.0030.00313.21
7.3.320.0000.00513.13
7.3.310.0040.00416.35
7.3.300.0000.00616.36
7.3.290.0030.00316.37
7.3.280.0070.01116.36
7.3.270.0130.01017.40
7.3.260.0110.00916.37
7.3.250.0090.00816.34
7.3.240.0100.00816.41
7.3.230.0060.01616.59
7.3.210.0090.00616.40
7.3.200.0060.01016.39
7.3.190.0100.00716.38
7.3.180.0060.01116.62
7.3.170.0060.00916.65
7.3.160.0130.00316.45
7.3.10.0090.00616.67
7.3.00.0090.00616.05
7.2.330.0060.01116.86
7.2.320.0070.01016.72
7.2.310.0110.00616.83
7.2.300.0100.00716.66
7.2.290.0030.01316.77
7.2.130.0090.00916.77
7.2.120.0130.00416.45
7.2.110.0140.01116.55
7.2.100.0160.00316.83
7.2.90.0190.00416.68
7.2.80.0220.00016.97
7.2.70.0080.00616.92
7.2.60.0140.00516.88
7.2.50.0090.01816.57
7.2.40.0100.00616.69
7.2.30.0180.00716.98
7.2.20.0100.00616.44
7.2.10.0110.00516.70
7.2.00.0110.00716.86
7.1.250.0070.01015.50
7.1.200.0060.00615.83
7.1.90.0520.01116.01
7.1.80.0290.00616.19
7.1.70.0340.00715.16
7.1.60.0470.01133.25
7.1.50.0580.01332.81
7.1.40.0490.01032.73
7.1.30.0530.01332.65
7.1.20.0600.01732.79
7.1.10.0320.01214.89
7.1.00.0340.01014.88
7.0.230.0530.00416.13
7.0.220.0370.00015.82
7.0.210.0360.01014.63
7.0.200.0460.00715.10
7.0.190.0410.01015.10
7.0.180.0350.01114.60
7.0.170.0540.00014.58
7.0.160.0550.01014.47
7.0.150.0350.00714.68
7.0.140.0470.00714.55
7.0.130.0640.00314.79
7.0.120.0320.01014.80
7.0.110.0360.00314.78
7.0.100.0540.01016.52
7.0.90.0040.01216.28
7.0.80.0090.00916.46
7.0.70.0030.00916.45
7.0.60.0100.00316.13
7.0.50.0030.01016.62
7.0.40.0090.00316.30
7.0.30.0060.00616.47
7.0.20.0120.00016.49
7.0.10.0030.00916.54
7.0.00.0000.01316.52

preferences:
119.31 ms | 403 KiB | 5 Q