Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98420 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68762 invoked from network); 7 Mar 2017 22:18:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Mar 2017 22:18:36 -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:60080] helo=outbound0.mail.transip.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/A5-27071-4B13FB85 for ; Tue, 07 Mar 2017 17:18:30 -0500 Received: from submission6.mail.transip.nl (submission6.mail.transip.nl [149.210.149.10]) by outbound0.mail.transip.nl (Postfix) with ESMTP id 3vd9z529lvz11TJf for ; Tue, 7 Mar 2017 23:18:25 +0100 (CET) Received: from mail-it0-f43.google.com (mail-it0-f43.google.com [209.85.214.43]) by submission6.mail.transip.nl (Postfix) with ESMTPA id 3vd9z33PnXz12LWl for ; Tue, 7 Mar 2017 23:18:23 +0100 (CET) Received: by mail-it0-f43.google.com with SMTP id m27so23501389iti.0 for ; Tue, 07 Mar 2017 14:18:23 -0800 (PST) X-Gm-Message-State: AMke39kKbPJBAAcS2/fepWgACm7ojg2n6ZRCTy7u2/byEr8gRxdCaKV9LiZzlUoOw0C0/OK1iWOc1nMPMOrZhw== X-Received: by 10.36.104.198 with SMTP id v189mr3574044itb.72.1488925102758; Tue, 07 Mar 2017 14:18:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.208.12 with HTTP; Tue, 7 Mar 2017 14:18:02 -0800 (PST) In-Reply-To: <466f3491-321f-2aca-ea5a-4128b07356df@gmail.com> References: <3d5cfa50-5f5d-5633-99ad-052a6b5ac599@gmail.com> <466f3491-321f-2aca-ea5a-4128b07356df@gmail.com> Date: Tue, 7 Mar 2017 23:18:02 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11449d56d8eff4054a2b6307 X-Scanned-By: ClueGetter at submission6.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?=) --001a11449d56d8eff4054a2b6307 Content-Type: text/plain; charset=UTF-8 Hi Rowan, On Sat, Mar 4, 2017 at 5:09 PM, Rowan Collins wrote: > > I haven't built with the patch to check, but have you checked it behaves > correctly with other combinations? For instance [-10 => true, -5 => true, > true] or ['string_key' => true, -10 => true, true] The first example behaves how you would expect with this patch (third element gets -4). In the second example however, it would act the "old" way. Thanks for the hint! I'm working on making it consistent in that case as well. Would you be willing to draft an RFC for this change? If you're not > familiar with the process, have a look at this: > https://blogs.oracle.com/opal/entry/the_mysterious_php_rfc_process Yes, I'm already familiar with it. It clearly seems to be the way forward so I'll create a draft once I'm done with the implementation fixes/further discussion. > - Exactly what behaviour will change, and how? We already have three > different things that are affected, and there may well be others. > If the first numeric index - n - of an array is negative (however that array is created), the next element (however it is inserted) will not default to 0, but will have the index n + 1. > - What code might rely on the current behaviour? What kind of bugs might > such code exhibit if it's not updated after the change? How can users write > code that will work the same before and after the change? > I have a hard time coming up with a use case for it but basically, any code relying on the defaulting to 0. Basically, the only safe way I see is that if you don't set explicit keys, you probably shouldn't try to access array elements by an explicit key. > - On the other side, what are the benefits of the change? What is the harm > caused by the current behaviour, e.g. potential for bugs or mistakes? > IMHO, the benefit is that you naturally expect a subsequent element to get the n+1 key regardless of n being positive or negative. The current implementation gives you an effect that you only discover once you hit it or read the manual page about array_fill or the note you mentioned before on the page about arrays. Regards, Pedro --001a11449d56d8eff4054a2b6307--