-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Support object types in BCMath #13741
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
[RFC] Support object types in BCMath #13741
Conversation
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 |
1dcfbc7
to
e118e60
Compare
I made a mistake in the PR 😱 |
Editing the comment was not enough so I will comment again. The following comment is incorrect. Actually, I was trying to comment on the next PR, but accidentally commented on this one. |
4693919
to
96c2ada
Compare
6946f43
to
0deefed
Compare
4c5c237
to
ad96f50
Compare
c3e7a8d
to
246219e
Compare
Co-authored-by: Niels Dossche <[email protected]>
bf73b54
to
0afc106
Compare
case IS_NULL: | ||
*lval = 0; | ||
return SUCCESS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is null
accepted here? This doesn't seem to be the case, looking at the signatures?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the same reason that there are problems with operators on GMP objects and null.
When merged this, it was intended to match the behavior of regular operators.
Since this behavior should be consistent, it would be best to discuss it together in my PR thread on GMP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.
| Q | A |------------- | ----------- | Type | feature | Fixed issues | #6644 #### Summary PHP 8.4 introduces a new `Number` class ([RFC](https://wiki.php.net/rfc/support_object_type_in_bcmath), php/php-src#13741) that feels like a perfect fit for `DECIMAL` values. This PR introduces a new `NumberType` class and a corresponding `Types::NUMBER` constant which maps decimal values to `Number` objects instead of plain strings.
https://wiki.php.net/rfc/support_object_type_in_bcmath
https://wiki.php.net/rfc/fix_up_bcmath_number_class