Re: Re: Support negative indexes for arrays and strings

From: Date: Mon, 03 Sep 2012 12:41:18 +0000
Subject: Re: Re: Support negative indexes for arrays and strings
Groups: php.internals 
Request: Send a blank email to internals+get-62735@lists.php.net to get a copy of this message
>as I understood, a lot of people seem to have problems with this proposal, since arrays and >strings could (and maybe >should) behave the same. The terminology "negative indexing" seems to imply that the feature should work with arrays. To restrict it to just strings might involve creating a term one would only associate with strings. >The main problem arises from the ambiguity for $array[-1] for arrays. >But this is easily solvable: just introduce a slice operator. > >$array[:-1] and the ambiguity is gone. Thanks for that suggestion! On the one hand, negative indexing alone is simpler and less prone to typos, but it makes sense that using the slice operator would clarify the code. SL

« previous php.internals (#62735) next »