[RFC] Deprecate implicit non-integer-compatible float to int conversions

php.internals

Girgias

5 years ago
Hello internals, This is a follow-up on the previous thread [1] about my RFC tackling implicit float to int conversion. It is now slightly larger in scope as it also pertains to what I call "non compatible integer floating numbers". This new version of the RFC can be found on the wiki: [2] https://wiki.php.net/rfc/implicit-float-int-deprecate Feedback is as usual welcomed, however I am not interested in changing the behaviour of explicit casts. One detail is if this RFC should also allow the usage of int compatible float strings for string offsets, behaviour which has been removed in PHP 8.0 with the Saner Numeric Strings RFC. [3] Best regards, George P. Banyard [1] "[RFC] Warning for implicit float to int conversions" https://externals.io/message/113077 [2] https://wiki.php.net/rfc/implicit-float-int-deprecate [3] https://wiki.php.net/rfc/saner-numeric-strings

Andreas Leathley

5 years ago
On 04.03.21 14:07, G. P. B. wrote:
> This new version of the RFC can be found on the wiki: [2] > https://wiki.php.net/rfc/implicit-float-int-deprecate
I like the RFC, but I think the diagnostic messages will be hard to understand when they come up in real scripts, especially because they can be platform-dependent and can have two different reasons, and "non-compatible" is not self-explanatory. Giving a very specific message would be more helpful for people experiencing these errors, something like: * Implicit conversion to int from float(-string) with fractional part * Implicit conversion to int from float(-string) which is outside of int range (=> maybe also mentioning the range of the platform) (Maybe there are additional possible errors to consider, but those two seem two obvious possibilities)

Girgias

5 years ago
On Thu, 4 Mar 2021 at 13:23, Andreas Leathley <a.leathley@gmx.net> wrote:
> On 04.03.21 14:07, G. P. B. wrote: > > This new version of the RFC can be found on the wiki: [2] > > https://wiki.php.net/rfc/implicit-float-int-deprecate > > I like the RFC, but I think the diagnostic messages will be hard to > understand when they come up in real scripts, especially because they > can be platform-dependent and can have two different reasons, and > "non-compatible" is not self-explanatory. Giving a very specific message > would be more helpful for people experiencing these errors, something like: > > * Implicit conversion to int from float(-string) with fractional part > * Implicit conversion to int from float(-string) which is outside of > int range (=> maybe also mentioning the range of the platform) > > (Maybe there are additional possible errors to consider, but those two > seem two obvious possibilities) >
The other cases would be converting from infinity (+ or -) or a NaN value. But having specific messages is a reasonable enhancement but does make the implementation more complicated as one needs to determine what is causing the incompatibility. I'll have a think about this. Best, George P. Banyard

Girgias

5 years ago
On Thu, 4 Mar 2021 at 17:49, G. P. B. <george.banyard@gmail.com> wrote:
> On Thu, 4 Mar 2021 at 13:23, Andreas Leathley <a.leathley@gmx.net> wrote: > >> On 04.03.21 14:07, G. P. B. wrote: >> > This new version of the RFC can be found on the wiki: [2] >> > https://wiki.php.net/rfc/implicit-float-int-deprecate >> >> I like the RFC, but I think the diagnostic messages will be hard to >> understand when they come up in real scripts, especially because they >> can be platform-dependent and can have two different reasons, and >> "non-compatible" is not self-explanatory. Giving a very specific message >> would be more helpful for people experiencing these errors, something >> like: >> >> * Implicit conversion to int from float(-string) with fractional part >> * Implicit conversion to int from float(-string) which is outside of >> int range (=> maybe also mentioning the range of the platform) >> >> (Maybe there are additional possible errors to consider, but those two >> seem two obvious possibilities) >> > > The other cases would be converting from infinity (+ or -) or a NaN value. > > But having specific messages is a reasonable enhancement but does make > the implementation more complicated as one needs to determine what is > causing > the incompatibility. > > I'll have a think about this. > > Best, > > George P. Banyard >
Amended the RFC and implementation so the incompatible-integer float value is shown in the deprecation warning. Latest version can as usual be found here: https://wiki.php.net/rfc/implicit-float-int-deprecate I would like to move this to voting at the end of the week as it's been about a month since the initial discussion about the RFC [1] started. Best regards, George P. Banyard [1] https://externals.io/message/113077