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 | More toots from timwolla@phpc.social
=> View php84 tag | View php tag This content has been proxied by September (3851b).Proxy Information
text/gemini