Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100256 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75093 invoked from network); 19 Aug 2017 13:30:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2017 13:30:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.175 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.175 mail-io0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:34109] helo=mail-io0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/88-34801-F6D38995 for ; Sat, 19 Aug 2017 09:30:24 -0400 Received: by mail-io0-f175.google.com with SMTP id g135so2139408iog.1 for ; Sat, 19 Aug 2017 06:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=VPXa5SQPP4hF6eBD5yF/LYzK++kyL6oYrISa2mplVIA=; b=Laztr8PxTKBv5awe6JhwkX3PRKf8a48gTkQmdNv71xihsPHq20kK1f51fF40pqVoR3 UH7jP1py0symZRSXQRbcSXm4spUWJeXUhpQyfyLj0Ic3jzh4St1/d9gtdsuT02zWUzgR P96T/MeM0j/UIEfb+bYiOD1rhMCDfMMle4BadYiJnOLf/BpDADoheUAOLN1FKDn3pbiR /9eKwbYdUXigMyXgbeKuadR36lrHXvFe8JrLcld+6BvGEEeXY/YJxgX340gtjGbxDPmW 6KTNW0WaA/9ZRj3C31U0edOSOdXnGJp9ZG87P2NHB4YQgnIqbnsXXCC1RiU1LIY3SsbH 36mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=VPXa5SQPP4hF6eBD5yF/LYzK++kyL6oYrISa2mplVIA=; b=cUShrj+lMjx19S3J7SG3q2/Zo38BbHFVigR5R6h/jdzI0p3MnfnyvpmMPycE3K4HPR eYrXchyVlHgpqIMG8T3VWfMIyvh0yCkGlshB5kq34iWmEsKHvQJ5yQp473vGBGdlZZRk qeAv5GyRkTb2RUGosqlrjkXjDD3z4CWrdvF2gQdjPt9ti0tn0NLrSliDqw7xNYY1/VFM 7+YKMf0nAOS4YawptRtA1XCMPx1STR1BAOFm11Zga+cLZ7XmCJx0hTLbnZgOBPBd5lZn o4cu6Zzl0JxDc1xj9IMNXx0rrEhBMEb/RpVkcFUa26+KfA5UsfyyCT9AXKc/k22v1UZG 7HLg== X-Gm-Message-State: AHYfb5jqfwY2F3cYoHsic8xAeH6TFCMgpiCJeFTOSB+gLECX9CtllGL7 ab+pAZBUMDFwC9h/ndNHcwyBnli9fg== X-Received: by 10.107.19.38 with SMTP id b38mr10754895ioj.285.1503149420238; Sat, 19 Aug 2017 06:30:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.13.3 with HTTP; Sat, 19 Aug 2017 06:30:19 -0700 (PDT) In-Reply-To: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> References: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> Date: Sat, 19 Aug 2017 15:30:19 +0200 Message-ID: To: Andrew Nester Cc: PHP internals Content-Type: multipart/alternative; boundary="001a113eeb183cdf1e05571b3f96" Subject: Re: [PHP-DEV] Re: [Request][Discussion] Double value as array key improvement From: nikita.ppv@gmail.com (Nikita Popov) --001a113eeb183cdf1e05571b3f96 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Aug 17, 2017 at 5:03 PM, Andrew Nester wrote: > > > > 13 =D0=B0=D0=B2=D0=B3. 2017 =D0=B3., =D0=B2 21:39, Andrew Nester > =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0): > > > > > > > >> 11 =D0=B0=D0=B2=D0=B3. 2017 =D0=B3., =D0=B2 15:53, Andrew Nester =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0): > >> > >> > >>> On Aug 11, 2017, at 2:10 PM, Andrew Nester wrote: > >>> > >>> Hello everyone! > >>> > >>> I was working on following request https://bugs.php.net/bug.php? > id=3D75053 which resulted in following pull request > https://github.com/php/php-src/pull/2676 > >>> > >>> The problem here is following: when we=E2=80=99re using large numbers= as array > index when adding new elements it could overwrite already existing value. > >>> Assume we have 2 indexes 5076964154930102272 and > 999999999999999999999999999999 with different value set for them. > >>> > >>> Because 999999999999999999999999999999 is larger than maximum long in= t > number for 64-bit systems, it will be converted to double. (corresponding > code here https://github.com/php/php-src/blob/master/Zend/zend_ > language_scanner.l#L1648) > >>> But when double value is used as array indexes, it is converted to > long integer. (f.e., code is here https://github.com/php/php- > src/blob/master/Zend/zend_execute.c#L1573) > >>> At this case it causes overflow and we=E2=80=99ve got index equal to > 5076964154930102272 and as a result - we=E2=80=99re overwriting previousl= y set > value. > >>> > >>> My suggestion is following: > >>> 1) when double key is less than maximum possible long integer - > convert it to integer > >>> 2) if it=E2=80=99s larger - convert it to string. > >>> > >>> That=E2=80=99s what implemented in proposed PR. > >>> > >>> Another possible option is just to throw warning in this case > (proposed by Nikita Popov) > >>> > >>> I would happy to hear any feedback and suggestions about this solutio= n. > >>> Thanks! > >> > >> Here is the alternative solution which emits E_WARNING in case of > integer array index overflow. > >> https://github.com/php/php-src/pull/2677 > > > > My preferred solution is 2nd one (emitting warning) as it more obvious > for users, doesn't break previous behaviour. > > > > Cheers, > > Andrew > > 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! 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). Nikita --001a113eeb183cdf1e05571b3f96--