Repository navigation
[RFC] Warn on implicit float to int conversions. - #6661
Conversation
3c517e1 to
0a268d4
Compare
63f887f to
32e94f0
Compare
32e94f0 to
d87efe5
Compare
TysonAndre
left a comment
There was a problem hiding this comment.
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
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 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.