<?php // storage class, PHP 8.3 needed class LazyValue { public function __construct(private Closure $lazy){} public function getValue() { static $value = ($this->lazy)(); return $value; } } // use $l1 = new LazyValue(function () { echo "slow\n"; return "42\n"; }); echo $l1->getValue(); echo $l1->getValue(); echo $l1->getValue();
You have javascript disabled. You will not be able to edit any code.