New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Prototype: Support object types in BCMath #13741
base: master
Are you sure you want to change the base?
[WIP] Prototype: Support object types in BCMath #13741
Conversation
Co-authored-by: Gina Peter Banyard <girgias@php.net>
Sorry for barging as end-user, but I am really interested if this RFC will allow lazy evaluation. For example: class LazyInt extends Number
{
private int|null $cachedValue = null;
/**
* @param Closure(): int $closure
*/
public function __construct(private Closure $closure){}
#[Override]
public function getValue(): int
{
return $this->cachedValue ??= ($this->closure)(); // one-time lazy evaluation
}
} and then use like: function slow(): int
{
sleep(5); // some slow query
return 42;
}
$lazy1 = new LazyInt(fn() => slow()); // nothing happens
$lazy2 = new LazyInt(fn() => slow()); // nothing happens
$lazy1 + $lazy2; // sleeps 10 seconds, returns Number(84);
$lazy1 + $lazy2; // no sleep, returns Number(84); This lazy evaluation has many use-cases, but it would require something like this: class Number extends \Stringable
{
public function getValue(): string|int;
} |
After much discussion, it was decided that this class should be marked final, so it cannot be inherited :) |
@SakiTakamachi Last one, I promise: will you be open to create |
Please see https://externals.io/message/122651
(This is a branch derived from #13096.)