Skip to content
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

Scalar Type Casting Magic Methods #14073

Open
kripper opened this issue Apr 29, 2024 · 2 comments
Open

Scalar Type Casting Magic Methods #14073

kripper opened this issue Apr 29, 2024 · 2 comments

Comments

@kripper
Copy link

kripper commented Apr 29, 2024

Description

When doing $obj + 123, $obj shouldn't be treated by PHP as a string when $obj is a numeric representation.
Adding the magic casting method __toscalar is handy for solving this.

Please release this patch.
See: https://wiki.php.net/rfc/object_cast_to_types

@Girgias
Copy link
Member

Girgias commented Apr 30, 2024

Surely what you want here is operator overloading rather than a __toScalar magic method?

@kripper
Copy link
Author

kripper commented May 1, 2024

Surely what you want here is operator overloading rather than a __toScalar magic method?

__toscalar would be prefered to also support the round($obj) + 1 use case.
I don't mind if the magic casting method is either called __toNumber or __toNumeric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants