Re: Re: [Request][Discussion] Double value as array key improvement

From: Date: Mon, 21 Aug 2017 15:04:16 +0000
Subject: Re: Re: [Request][Discussion] Double value as array key improvement
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-100270@lists.php.net to get a copy of this message
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/

« previous php.internals (#100270) next »