Re: Support negative indexes for arrays and strings

From: Date: Mon, 11 Jun 2012 20:25:46 +0000
Subject: Re: Support negative indexes for arrays and strings
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-60795@lists.php.net to get a copy of this message
On 11/06/12 20:28, Richard Lynch wrote:
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]; If $n is a negative value, an E_NOTICE will be triggered. To not do
if ($n< 0){ //whatever } else{ //something entirely different } Prior to your string offset can be looked at being bad practice.


« previous php.internals (#60795) next »