Hi everyone,

Nikita Popov wrote:

Sounds good to me. Something you might want to consider is to also throw a
warning if the floating point number is not an exact integer. For example
allow a silent cast of 42.0 to 42, but throw a warning if 42.5 is used as
an index (or worse, 42.999999999, in which case it likely isn't doing what
the programmer thinks it's doing).

I wonder about whether this is a good idea. I've previously suggested something like this myself, but at the present time, I'd be more concerned about consistent behaviour. We do silent casts from floats to integers in other places in PHP. Array indices aren't that special. Moreover, this implicit truncation behaviour is useful in some cases.

--
Andrea Faulds
https://ajf.me/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to