3v4l.org

run code in 500+ PHP versions simultaneously
<?php class FakeCollection { public function __construct(private array $items) {} public function sum(string $key): float { $total = 0; foreach ($this->items as $item) { $total += $item[$key]; } return $total; } } function collect(array $items): FakeCollection { return new FakeCollection($items); } class FakePayment { public array $credits = []; public function __construct(public float $amount, public float $refunded) {} public function credits() { return new class { public function exists(): bool { return false; } }; } } function checkTotalRefundableAmount($payment, array $request_invoices, array $input): bool { // Calculate total refund amount requested $total_refund_requested = 0; if (count($request_invoices) > 0) { $total_refund_requested = collect($request_invoices)->sum('amount'); } elseif (array_key_exists('amount', $this->input)) { $total_refund_requested = $this->input['amount']; } if ($total_refund_requested <= 0) { return true; // No refund requested } // Calculate maximum refundable from cash portion $max_cash_refund = $payment->amount - $payment->refunded; // Calculate maximum refundable from credits $max_credit_refund = 0; if ($payment->credits()->exists()) { foreach ($payment->credits as $credit) { $max_credit_refund += ($credit->pivot->amount - $credit->pivot->refunded); } } $max_total_refundable = $max_cash_refund + $max_credit_refund; if ($total_refund_requested > $max_total_refundable) { return false; } return true; } $payment = new FakePayment(amount: 30.20, refunded: 0.0); $invoices = [['invoice_id' => 'INV_1', 'amount' => 11.85], ['invoice_id' => 'INV_2', 'amount' => 18.35]]; var_dump(checkTotalRefundableAmount($payment, $invoices, ['id' => 'PAYMENT_ID'])); // bool(false) — should be true

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.5.100.0110.00818.64
8.5.90.0100.00618.67
8.5.80.0100.00618.58
8.5.70.0090.00718.54
8.5.60.0080.00618.61
8.5.50.0070.00718.43
8.5.40.0090.00718.48
8.5.30.0070.00618.37
8.5.20.0100.00718.37
8.5.10.0090.00718.38
8.5.00.0100.00618.39
8.4.250.0090.00921.47
8.4.240.0090.00821.43
8.4.230.0110.00921.45
8.4.220.0100.00721.37
8.4.210.0100.00821.40
8.4.200.0100.01021.45
8.4.190.0080.00821.56
8.4.180.0100.00721.49
8.4.170.0070.00821.60
8.4.160.0080.00821.58
8.4.150.0090.00921.55
8.4.140.0080.00619.52
8.4.130.0070.00619.49
8.4.120.0050.00519.63
8.4.110.0050.00519.59
8.4.100.0060.00619.64
8.4.90.0070.00419.63
8.4.80.0070.00719.65
8.4.70.0070.00519.68
8.4.60.0070.00419.63
8.4.50.0100.00719.62
8.4.40.0100.00519.54
8.4.30.0100.00619.64
8.4.20.0090.00719.68
8.4.10.0090.00719.64
8.3.330.0090.00720.18
8.3.320.0090.00720.23
8.3.310.0090.00620.18
8.3.300.0100.00620.19
8.3.290.0080.00820.11
8.3.280.0090.00720.18
8.3.270.0090.00618.55
8.3.260.0070.00718.56
8.3.250.0070.00718.54
8.3.240.0080.00418.62
8.3.230.0070.00518.58
8.3.220.0070.00518.51
8.3.210.0070.00618.53
8.3.200.0090.00418.51
8.3.190.0070.00718.57
8.3.180.0060.00618.58
8.3.170.0070.00518.54
8.3.160.0060.00418.61
8.3.150.0080.00618.59
8.3.140.0080.00618.56
8.3.130.0080.00718.56
8.3.120.0070.00518.57
8.3.110.0080.00518.50
8.3.100.0080.00818.56
8.3.90.0100.00518.57
8.3.80.0100.00618.55
8.3.70.0120.00518.55
8.3.60.0110.00618.60
8.3.50.0110.00618.54
8.3.40.0110.00619.87
8.3.30.0120.00719.75
8.3.20.0120.00719.83
8.3.10.0100.00919.82
8.3.00.0120.00619.82
8.2.330.0090.00919.94
8.2.320.0090.00719.93
8.2.310.0070.00919.88

preferences:
47.02 ms | 783 KiB | 5 Q