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

Fix GH-15968: Avoid converting objects to strings in operator calculations. #16021

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

SakiTakamachi
Copy link
Member

@SakiTakamachi SakiTakamachi commented Sep 24, 2024

fixes #15968

As Gina commented, there was a problem with the function I was using.
#15968 (comment)

There are almost no cases where want to treat a stringable class other than the Number class as a string in operator calculations, so modify it so that the object is not converted to a string.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me but lets see if @cmb69 has any opinions about this.

@SakiTakamachi
Copy link
Member Author

Thanks!

I plan to include this in RC1. At least it's better than leaving it as it is now.

@cmb69
Copy link
Member

cmb69 commented Sep 24, 2024

Well, in coercive typing mode I would expect a class implementing __toString() to be silently converted to string, if a function is declared to accept a string. I'm aware that GMP doesn't behave that way, what I consider a bug, but since it's works like this for a long time, I won't fight it.

@SakiTakamachi
Copy link
Member Author

SakiTakamachi commented Sep 24, 2024

hmm...

For now, I will adopt this PR, but it might be worth considering making a "bug fix" in the next version or later, including the GMP issue.

edit:
The basic behavior of the operator doesn't seem to take __toString() into account.
https://3v4l.org/FkZLC

@SakiTakamachi SakiTakamachi merged commit c5b258f into php:master Sep 24, 2024
1 of 2 checks passed
@SakiTakamachi SakiTakamachi deleted the fix/gh-15968 branch September 24, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BCMath\Number operators may typecast operand
3 participants