-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Warn on implicit float to int conversions. #6661
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
Conversation
3c517e1
to
0a268d4
Compare
63f887f
to
32e94f0
Compare
32e94f0
to
d87efe5
Compare
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.
I don't see any issues with this pr at a glance, only nits. I'm not familiar enough with opcache/jit to know if anything else needs to be changed.
I'd personally consider this an improvement over silently allowing the loss of precision, especially for array keys
Also, I think this will work with negative zero but it'd be useful to have at least one test case in case the implementation ever changes or the JIT ever unintentionally differs on some platforms. https://en.wikipedia.org/wiki/Signed_zero#Comparisons mentions
According to the IEEE 754 standard, negative zero and positive zero should compare as equal with the usual (numerical) comparison operators, like the == operators of C and Java.
(i.e. since PHP's ===
uses C's ==
for floats I don't expect issues)
php > $negativeZero = -0.0;
php > var_dump($negativeZero);
float(-0)
php > var_dump($negativeZero === (float)(int)$negativeZero);
bool(true)
php > var_dump($negativeZero === 0.0);
bool(true)
d87efe5
to
4d1be39
Compare
4d1be39
to
a92b3e5
Compare
7278201
to
adfc720
Compare
dd057df
to
51a75e5
Compare
Zend/tests/float_to_int/warning_float_does_not_fit_zend_long_write_variation1.phpt
Outdated
Show resolved
Hide resolved
Zend/tests/float_to_int/warning_float_does_not_fit_zend_long_write_variation2.phpt
Outdated
Show resolved
Hide resolved
…eck multiple times
Mark test as XFAIL as I don't understand why this doens't generate a warning on 64bits This reverts commit 75c008a.
e719449
to
09a8044
Compare
Thank you @Girgias for this, and congratulations on the unanimous RFC vote yes. Really trying not to bike-shed, but do you think using We already use If you think it's a good idea, I would gladly send a PR through. I apologize if the choice of Thank you. |
Feel free to send a PR, I didn't think a lot about the deprecation message to be honest (and it's been a while). :-) |
Updates the deprecation message for implicit incompatible float to int conversion from: ``` Implicit conversion from non-compatible ``` to ``` Implicit conversion from incompatible ``` Related: php#6661
Updates the deprecation message for implicit incompatible float to int conversion from: ``` Implicit conversion from non-compatible float %.*H to int in %s on line %d ``` to ``` Implicit conversion from float %.*H to int loses precision in %s on line %d ``` Related: php#6661
Updates the deprecation message for implicit incompatible float to int conversion from: ``` Implicit conversion from non-compatible float %.*H to int in %s on line %d ``` to ``` Implicit conversion from float %.*H to int loses precision in %s on line %d ``` Related: php#6661
Updates the deprecation message for implicit incompatible float to int conversion from: ``` Implicit conversion from non-compatible float %.*H to int in %s on line %d ``` to ``` Implicit conversion from float %.*H to int loses precision in %s on line %d ``` Related: #6661
Relatively straight forward implementation, might need to check OPcache.
RFC is located here: https://wiki.php.net/rfc/implicit-float-int-deprecate.