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

From: Date: Thu, 31 Aug 2017 00:57:17 +0000
Subject: Re: [Request][Discussion] Double value as array key improvement
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-100330@lists.php.net to get a copy of this message
Hi there, Andrew Nester wrote:
Hello internals! I was working on solution for the problem of double to int conversion for array indices and would like to create an RFC for proposed solution - emitting warning when integer overflow happens during double to int conversion. Does it look like good idea? Thanks!
It's certainly an improvement over silently truncate-wrapping like at present. But one question I might have is whether there's any benefit to it just being a warning rather than an Error. Surely nobody would rely on this behaviour? I can't imagine a use-case where it doing % 2^64 on your indices is helpful. Who would want the code execution to continue beyond that point? Will someone want to silence this error? Compare how the int type declaration on userland functions handles floats like these: it throws a TypeError. Internal functions *do* throw a warning, but they don't execute their body and return NULL instead (they do throw a TypeError in strict mode). If you threw some kind of Error instead, I can't imagine it causing backwards-compatibility problems in practice, and at least personally, I think it would be the better choice. But I wrote the RFC that made passing floats > PHP_INT_MAX or < PHP_INT_MIN to functions with integer parameters produce those errors, so of course I'd say that… Anyway, thanks for bringing this up! It's something that I've wanted to fix since a long time ago and had forgotten about. -- Andrea Faulds https://ajf.me/

« previous php.internals (#100330) next »