3v4l.org

run code in 300+ PHP versions simultaneously
<?php class OrderItem { public int $order_id; public string $sku; public int $quantity; } class OrderItems { static function get(int $order_id):array { static $times = 0; if ( 0 !== $times ) { trigger_error('If this happens then the second call to callAndSet() evaluated the closure again.'); $times = 1; } // Simulating a two item order $item = new OrderItem(); $item->order_id = $order_id; $item->sku = 'ABC-123'; $item->quantity = 12; $item2 = new OrderItem(); $item2->order_id = $order_id; $item2->sku = 'XYZ-987'; $item2->quantity = 5; return [$item,$item2]; } } function callAndSet(mixed &$lazy) { return $lazy instanceof Closure ? $lazy = $lazy() : $lazy; } class Order { public int $order_id; public Closure|array $order_items; function __construct(int $order_id) { $this->order_id = $order_id; $this->order_items = fn() => OrderItems::get($order_id); } } $order = new Order(123); foreach( callAndSet($order->order_items) as $order_item) { printf("%d of %s\n", $order_item->quantity, $order_item->sku); } echo "---\n"; foreach( callAndSet($order->order_items) as $order_item) { printf("%d of %s\n", $order_item->quantity, $order_item->sku); } echo "---\n"; foreach( $order->order_items as $order_item) { printf("%d of %s\n", $order_item->quantity, $order_item->sku); }

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.130.0080.00018.53
8.3.120.0060.00319.12
8.3.110.0060.01320.94
8.3.100.0130.00624.06
8.3.90.0040.00426.77
8.3.80.0000.01016.66
8.3.70.0060.00916.75
8.3.60.0150.00618.43
8.3.50.0090.01216.52
8.3.40.0110.01118.72
8.3.30.0160.00018.75
8.3.20.0040.00424.18
8.3.10.0000.00724.66
8.3.00.0050.00326.16
8.2.250.0070.00716.86
8.2.240.0100.00017.12
8.2.230.0120.00422.58
8.2.220.0050.00337.54
8.2.210.0080.00026.77
8.2.200.0080.00416.75
8.2.190.0080.00816.63
8.2.180.0030.01225.92
8.2.170.0140.00419.08
8.2.160.0100.00322.96
8.2.150.0040.00425.66
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0070.00021.13
8.2.110.0090.00020.46
8.2.100.0060.00620.38
8.1.300.0120.00919.80
8.1.290.0000.00930.84
8.1.280.0090.00625.92
8.1.270.0050.00323.99
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0050.00520.39
8.1.230.0080.00321.99
8.1.100.0070.00517.36
8.0.80.0080.00916.98
7.4.300.0020.00516.42
7.4.190.0030.00516.34

preferences:
44.19 ms | 403 KiB | 5 Q