3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sql(callable $expr): array { if ($context = (new \ReflectionFunction($expr))->getClosureThis()) { $placeholder = new class($context) { private object $context; private ReflectionObject $reflection; public function __construct(object $context) { $this->context = $context; $this->reflection = new \ReflectionObject($context); } public function __call($method, $args) { $method = $this->reflection->getMethod($method); return $method->getClosure($this->context)->call($this->context, ...$args); } public function __get($property) { $property = $this->reflection->getProperty($property); $property->setAccessible(true); return $property->getValue($this->context); } public function __isset($property): bool { return $this->reflection->hasProperty($property); } public function __set($property, $value): void { $property = $this->reflection->getProperty($property); $property->setAccessible(true); $property->setValue($this->context, $value); } public function __toString(): string { return '?'; } }; } else { $placeholder = new class { public function __toString(): string { return '?'; } }; } $expr = Closure::fromCallable($expr) ->bindTo($placeholder, $placeholder); $params = []; $generator = $expr(); while ($generator->valid()) { $params[] = $generator->current(); // Get the value from "yield" $generator->send('this'); // Insert placeholder } return [$generator->getReturn(), $params]; } class Foo { private int $id = 42; public function bar(): void { [$query, $params] = sql(fn() => "SELECT * FROM users WHERE id = ${yield $this->id} OR username = ${yield $this->username()}"); var_dump( $query, $params, ); } private function username(): string { return 'azjezz'; } } $f = new Foo(); $f->bar();

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.130.0060.00618.56
8.4.120.0130.00724.29
8.4.110.0110.00922.41
8.4.100.0120.00918.12
8.4.90.0120.01018.76
8.4.80.0050.00519.65
8.4.70.0090.00718.92
8.4.60.0120.00718.72
8.4.50.0130.00618.93
8.4.40.0060.00317.80
8.4.30.0170.00320.36
8.4.20.0160.00019.76
8.4.10.0040.00418.88
8.3.260.0100.01016.99
8.3.250.0110.00718.91
8.3.240.0080.01117.37
8.3.230.0140.00516.94
8.3.220.0120.00617.04
8.3.210.0120.00818.34
8.3.200.0040.00516.66
8.3.190.0100.00917.03
8.3.180.0100.00819.18
8.3.170.0120.00320.86
8.3.160.0120.00617.33
8.3.150.0110.00717.29
8.3.140.0180.00016.58
8.3.130.0030.00616.81
8.3.120.0030.00620.90
8.3.110.0060.00320.94
8.3.100.0070.01316.77
8.3.90.0040.01226.77
8.3.80.0060.00616.88
8.3.70.0130.00916.88
8.3.60.0110.01116.88
8.3.50.0090.00618.37
8.3.40.0060.01219.36
8.3.30.0000.01518.79
8.3.20.0080.00024.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.290.0050.00320.60
8.2.280.0110.00816.61
8.2.270.0070.00317.40
8.2.260.0030.00516.88
8.2.250.0100.00016.75
8.2.240.0030.00619.05
8.2.230.0070.00322.58
8.2.220.0110.00024.06
8.2.210.0080.00026.77
8.2.200.0100.00018.29
8.2.190.0120.00616.63
8.2.180.0040.01125.92
8.2.170.0120.00318.83
8.2.160.0140.00022.96
8.2.150.0040.00425.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00426.16
8.2.110.0040.00722.13
8.2.100.0030.00918.02
8.2.90.0000.00917.87
8.2.80.0040.00417.97
8.2.70.0080.00017.50
8.2.60.0080.00018.03
8.2.50.0090.00018.07
8.2.40.0040.00418.22
8.2.30.0000.00818.09
8.2.20.0000.00719.57
8.2.10.0040.00418.80
8.2.00.0080.00019.36
8.1.330.0110.00821.80
8.1.320.0110.00517.84
8.1.310.0050.00318.32
8.1.300.0140.00016.08
8.1.290.0040.00730.84
8.1.280.0130.00625.92
8.1.270.0060.00323.80
8.1.260.0090.00026.35
8.1.250.0080.00028.09
8.1.240.0040.00422.22
8.1.230.0120.00019.21
8.1.220.0050.00317.80
8.1.210.0000.00818.77
8.1.200.0060.00317.48
8.1.190.0040.00417.23
8.1.180.0000.00918.10
8.1.170.0080.00018.69
8.1.160.0040.00418.86
8.1.150.0000.00818.61
8.1.140.0040.00417.42
8.1.130.0000.00718.95
8.1.120.0000.01017.50
8.1.110.0040.00417.48
8.1.100.0000.00817.52
8.1.90.0000.00717.52
8.1.80.0030.00617.53
8.1.70.0030.00317.57
8.1.60.0090.00017.55
8.1.50.0030.00617.54
8.1.40.0000.00917.40
8.1.30.0030.00617.70
8.1.20.0000.00817.55
8.1.10.0050.00317.64
8.1.00.0000.00817.43
8.0.300.0030.00919.79
8.0.290.0080.00316.62
8.0.280.0040.00418.53
8.0.270.0070.00017.22
8.0.260.0060.00018.49
8.0.250.0000.00716.93
8.0.240.0000.00717.02
8.0.230.0000.00817.06
8.0.220.0070.00016.98
8.0.210.0020.00517.01
8.0.200.0030.00316.99
8.0.190.0040.00417.07
8.0.180.0000.00716.92
8.0.170.0040.00417.00
8.0.160.0060.00317.00
8.0.150.0020.00516.90
8.0.140.0000.00716.93
8.0.130.0000.00613.39
8.0.120.0030.00516.95
8.0.110.0030.00516.88
8.0.100.0030.00616.96
8.0.90.0040.00417.00
8.0.80.0070.00017.03
8.0.70.0040.00417.00
8.0.60.0000.00816.96
8.0.50.0000.00816.89
8.0.30.0040.00417.00
8.0.20.0000.00716.92
8.0.10.0000.00917.03
8.0.00.0000.00817.15
7.4.330.0000.00515.55
7.4.320.0020.00516.55
7.4.300.0000.00616.64
7.4.290.0000.00716.45
7.4.280.0090.00316.47
7.4.270.0030.00316.49
7.4.260.0070.00013.21
7.4.250.0000.00816.59
7.4.240.0040.00416.60
7.4.230.0050.00216.66
7.4.220.0000.00716.62
7.4.210.0050.00216.66
7.4.200.0040.00416.53
7.4.190.0040.00416.69
7.4.180.0000.00916.67
7.4.160.0030.00516.67
7.4.150.0000.00716.50
7.4.140.0080.00016.52
7.4.130.0020.00516.43
7.4.120.0030.00516.35
7.4.110.0000.00816.57
7.4.100.0070.00016.66
7.4.90.0000.00816.49
7.4.80.0040.00416.55
7.4.70.0040.00416.63
7.4.60.0030.00516.58
7.4.50.0030.00516.41
7.4.40.0000.00716.44
7.4.30.0040.00416.47
7.4.20.0040.00416.43
7.4.10.0050.00316.43
7.4.00.0050.00316.49
7.3.330.0000.00716.10
7.3.320.0050.00012.96
7.3.310.0030.00316.16
7.3.300.0000.00816.04
7.3.290.0040.00416.18
7.3.280.0070.00016.21
7.3.270.0080.00016.02
7.3.260.0040.00416.30
7.3.250.0070.00016.11
7.3.240.0040.00416.23
7.3.230.0040.00416.04
7.3.220.0030.00316.04
7.3.210.0050.00516.15
7.3.200.0050.00515.91
7.3.190.0040.00415.95
7.3.180.0030.00516.04
7.3.170.0070.00016.03
7.3.160.0040.00416.10
7.3.150.0040.00416.25
7.3.140.0050.00516.05
7.3.130.0070.00016.12
7.3.120.0040.00416.20
7.3.110.0000.00715.86
7.3.100.0030.00316.14
7.3.90.0000.00716.30
7.3.80.0050.00216.05
7.3.70.0040.00416.24
7.3.60.0050.00316.21
7.3.50.0070.00016.17
7.3.40.0050.00316.36
7.3.30.0020.00516.05
7.3.20.0090.00316.18
7.3.10.0030.00416.03
7.3.00.0040.00416.37

preferences:
114.85 ms | 403 KiB | 5 Q