Really looking forward to be able to use property hooks with #php84.
use function array_pop as p;
final class Calculator {
private $s = [];
public float $v { get => end($this->s); set { $this->s[] = $value; } }
public null $add { get { $s = &$this->s; $s[] = p($s) + p($s); return null; } }
public null $mul { get { $s = &$this->s; $s[] = p($s) * p($s); return null; } }
}
$c = new Calculator();
$c->v = 2;
$c->v = 20;
$c->v = 2;
$c->mul;
$c->add;
var_dump($c->v);
[#]PHP
=> More informations about this toot | View the thread
Really looking forward to be able to use property hooks with #php84:
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
=> More informations about this toot | View the thread
Really looking forward to be able to write code like this with #php84:
if (!new Foo()->bar() instanceof Baz) {
echo "Didn't get a Baz\n";
}
=> More informations about this toot | View the thread
=> This profile with reblog | Go to timwolla@phpc.social account This content has been proxied by September (3851b).Proxy Information
text/gemini