Re: Support negative indexes for arrays and strings

From: Date: Mon, 03 Sep 2012 01:02:05 +0000
Subject: Re: Support negative indexes for arrays and strings
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-62700@lists.php.net to get a copy of this message
On 03.09.2012, at 01:11, slevy1@pipeline.com wrote: >> I see how this may work for strings and simple vectors, but what about this: >> >> $a = array(-1 => "foo", -2 => "bar"); echo $a[-1]; >> >> It should keep returning "foo", right? So then the question is - what >> $array[-1] actually means? > > Context would be the deciding factor, i.e. perhaps restrict the shortcut's applicability > to only a positive sequence of numbers for an indexed array's keys, as follows: > > $a = array(10 => "pen", 11 => "heaven"); > echo $a[-1]; // "heaven" You clearly haven't thought this through. What if my code wants to check for the existance of an array index "-1", and it doesn't know what kind of array gets passed in? For an index "-1", a value would exist, and for a "sequential" array, it would exist as well. This is an insane can of worms.

Attachment: [application/pkcs7-signature] smime.p7s
« previous php.internals (#62700) next »