Wed, 23 Oct 2024 13:39:51 +0000
php84, php

Really looking forward to be able to use property hooks with #php84:

<?php

final class Calculator
{
public Closure $add { get => static fn (int|float $a, int|float $b) => $a + $b; }
public Closure $subtract { get => static fn (int|float $a, int|float $b) => $a - $b; }
public Closure $multiply { get => static fn (int|float $a, int|float $b) => $a * $b; }
}

$myCalculator = new Calculator();
var_dump(($myCalculator->add)(40, 2));
var_dump(($myCalculator->multiply)(21, 2));

#PHP