Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98389 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7980 invoked from network); 2 Mar 2017 23:11:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Mar 2017 23:11:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=mail@pmmaga.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mail@pmmaga.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain pmmaga.net designates 149.210.149.69 as permitted sender) X-PHP-List-Original-Sender: mail@pmmaga.net X-Host-Fingerprint: 149.210.149.69 outbound0.mail.transip.nl Received: from [149.210.149.69] ([149.210.149.69:50020] helo=outbound0.mail.transip.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/FA-20342-796A8B85 for ; Thu, 02 Mar 2017 18:11:21 -0500 Received: from submission5.mail.transip.nl (submission5.mail.transip.nl [149.210.149.125]) by outbound0.mail.transip.nl (Postfix) with ESMTP id 3vZ7NN39Yxz11SNy for ; Fri, 3 Mar 2017 00:11:16 +0100 (CET) Received: from mail-io0-f181.google.com (mail-io0-f181.google.com [209.85.223.181]) by submission5.mail.transip.nl (Postfix) with ESMTPA id 3vZ7NJ6F1Dz7vXb for ; Fri, 3 Mar 2017 00:11:12 +0100 (CET) Received: by mail-io0-f181.google.com with SMTP id f84so63117878ioj.0 for ; Thu, 02 Mar 2017 15:11:12 -0800 (PST) X-Gm-Message-State: AMke39m/o3/kxCZHXwV80H6YpkjnvrRUIplH8W9JcmayZp+HpOnKvsakkrr2S/cYUuiU7xx4CBPdm9TMstiN1A== X-Received: by 10.107.4.75 with SMTP id 72mr255040ioe.162.1488496271325; Thu, 02 Mar 2017 15:11:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.208.12 with HTTP; Thu, 2 Mar 2017 15:10:50 -0800 (PST) In-Reply-To: <3d5cfa50-5f5d-5633-99ad-052a6b5ac599@gmail.com> References: <3d5cfa50-5f5d-5633-99ad-052a6b5ac599@gmail.com> Date: Fri, 3 Mar 2017 00:10:50 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113d905e8087f80549c78b92 X-Scanned-By: ClueGetter at submission5.mail.transip.nl X-Report-Abuse-To: abuse@transip.nl Subject: Re: [PHP-DEV] Re: On arrays starting with a negative index From: mail@pmmaga.net (=?UTF-8?Q?Pedro_Magalh=C3=A3es?=) --001a113d905e8087f80549c78b92 Content-Type: text/plain; charset=UTF-8 Hi Rowan, On Thu, Mar 2, 2017 at 11:39 PM, Rowan Collins wrote: > > Would other behaviour also be affected? > > For instance: > > $foo = [ -2 => true ]; > $foo[] = true; > $foo[] = true; > var_dump($foo); > > If so, this is a much wider BC break; if not, why not? > It would indeed. Internally, nNextFreeElement is initialized with 0 and updates on larger values. In the PR ( https://github.com/php/php-src/pull/2383/files#diff-fd78a0a3f78ea28c6907f907f25b908eR798 ) I'm allowing it to be set to a negative value if it is the first element. > Currently, this is completely consistent: https://3v4l.org/hXAsf Indeed, > I would say this is the missing explanation of why array_fill works the way > it does. With this PR all of your examples would behave consistently but with the negative indexes. > As mentioned above, if no key is specified, the maximum of the existing >> integer indices is taken, and the new key will be that >> > maximum value plus 1 (but at least 0). If no integer indices exist yet, > the key will be 0 (zero). > The "but at least 0" is exactly what this PR would change. > The point right now is that array_fill's behaviour is actually consistent > with the rest of the language, and while the value of that behaviour is > questionable, changing it now would be a major decision. I completely agree on the impact of this change. But I also believe that this behaviour would be preferable. Thank you for the feedback. Regards, Pedro --001a113d905e8087f80549c78b92--