Hi Rowan, On Sat, Mar 4, 2017 at 5:09 PM, Rowan Collins <rowan.coll...@gmail.com> 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