Re: Support negative indexes for arrays and strings

From: Date: Mon, 11 Jun 2012 19:28:21 +0000
Subject: Re: Support negative indexes for arrays and strings
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-60792@lists.php.net to get a copy of this message
On Mon, June 11, 2012 2:13 pm, Stas Malyshev wrote: >> And then one would expect some rather complex logic to compute -N >> for >> $var[-N] > > I don't see much of complex logic here, but $a[2] = 'a' would create a > new array element if it does not exist, while $a[-2] can't. Not a big > issue, but somewhat inconsistent I guess. $n = some_incredibly_long_and_complex_computation(); //and, for real fun, sometimes it returns positive, and sometimes negative. $s = $var[$n]; //a few hundred lines later, buried somewhere else if ($n < 0){ //whatever } else{ //something entirely different } Sooner or later, somebody will do that, and I really don't want to have to un-tangle all that mess to figure out if $n is positive or negative for the sake of saving a few keystrokes... -- brain cancer update: http://richardlynch.blogspot.com/search/label/brain%20tumor Donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE

« previous php.internals (#60792) next »