Mon, 28 Oct 2024 10:40:12 +0000
php84, php

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

<?php

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