Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104360 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63366 invoked from network); 12 Feb 2019 15:39:31 -0000 Received: from unknown (HELO mail-it1-f174.google.com) (209.85.166.174) by pb1.pair.com with SMTP; 12 Feb 2019 15:39:31 -0000 Received: by mail-it1-f174.google.com with SMTP id z7so6744410iti.0 for ; Tue, 12 Feb 2019 04:22:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BBU5ERZg6TSeiO4vNQpIayVd+oCM0Jb3MPxIp3HiVPM=; b=ZexES/wW1xH3SjmYY1o3tQQf03CH467qYx50cV/hPmtJVs/LdnI6OGV8MPQHTKBUtJ wo/ms4NY+AoEdJKg4NavVM+iOzqxUI1hVZ0WkdxDf+2es3DxKUS1eSMZ0vLUPoeniJAO K1aEnzMjIalRMbqJLwMuDO5neBWUrCHOFnSx0qr1QfbU8OtBXl/ykunCceU8AJdGsLXY U0AtSgwys26Tf+g21KStCidCnUl6SPIAmflaZws1GyIlX+NkthphUIq5J2MBjhHKck+v Ed2j689AYaZ+Xa5Hmongqzyh9mb9ozcVyIv3xAN9q5rRgpf+Bq3k1doq4TgpTApdWXIE QI3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BBU5ERZg6TSeiO4vNQpIayVd+oCM0Jb3MPxIp3HiVPM=; b=heI7q8NswLeUfZiSLM5RIYnlNxnm4EHLL8DaBH9hb5VEfpP25xorOkGbcG8vmp3YFh FK1YiZ4kGtLbiSsr2l6m+waRY7lXbmfbNcHisWAuRE5aRpst7FPkbiMzQGUWFz3upX1I rxtsrWIVPRQoVjkpQUPe+/vKKbrRu5wsU4lG++nWb/Dpn3VJnbE7geEQho8GP39i8iIq I0QsRXld1N4RflHyDxuQAXBvP9L0q3kW1x+PfWVXih4W1D+oRURnGeDGp0f8x2xO3ele YPL/Y3UQknmI0ACRReNVvwRdkEM01lwMkwrKk9ZLsKSMuySs9eQ2le0t56R6y8gHU5ma XX+g== X-Gm-Message-State: AHQUAuYNIBNQtkx4mrCEJ4W8seqPuJNP7yYV/QLsLSyrBQTKOA40Yp2g 8aDt1NI9c7adR/uKugAwYiQGvDMe8EYN3rx+7y4= X-Google-Smtp-Source: AHgI3IaOvgl4irBM3rzZZxXhdA+JgrKEwXPtq4gn5IhIPVHz4YMXia1c/6XCfCBRyXUSKaXDLKAsXwUTp8WPcBgE9kk= X-Received: by 2002:a5d:91d3:: with SMTP id k19mr1820152ior.258.1549974143646; Tue, 12 Feb 2019 04:22:23 -0800 (PST) MIME-Version: 1.0 References: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> <20.B2.14408.0FE57A95@pb1.pair.com> In-Reply-To: <20.B2.14408.0FE57A95@pb1.pair.com> Date: Tue, 12 Feb 2019 13:22:07 +0100 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003e40e60581b17a2d" Subject: Re: [PHP-DEV] Re: [Request][Discussion] Double value as array key improvement From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003e40e60581b17a2d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Aug 31, 2017 at 2:58 AM Andrea Faulds wrote: > 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=E2=80=A6 > > Anyway, thanks for bringing this up! It's something that I've wanted to > fix since a long time ago and had forgotten about. > (Bumping an old discussion here) I think the parallel with how we handle this for int parameters is a good one, and it would make sense to throw a TypeError when trying to use an out of range float key in an array. I'm slightly uneasy about the value-dependent behavior (e.g. your code might start throwing because the user entered a particularly large value somewhere). However, the argument applies to parameter handling in the same way, and as far as I know our behavior there has never proven to be a problem. And as using an out of range value essentially produces a nonsense result (say a negative number though your input was positive), I think pointing out the issue with a TypeError would be a win anyway... Nikita --0000000000003e40e60581b17a2d--