Re: Negative string offsets

From: Date: Thu, 17 Apr 2014 13:16:06 +0000
Subject: Re: Negative string offsets
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-73718@lists.php.net to get a copy of this message
On Thu, Apr 17, 2014 at 2:11 PM, Christian Stoller <stoller@leonex.de>wrote: > > On Thu, Apr 17, 2014 at 01:01:44PM +0100, Leigh wrote: > > > > > > What are peoples thoughts on allowing negative string offsets, that > > return > > > characters from the end of a string. > > > > > > Example: > > > > > > $string = 'foobar'; > > > print $string[-1]; // prints 'r'; > > > print $string[-2]; // prints 'a'; > > > > Generally I like this, but I think it's confusing and inconsistent in > comparison to array-indiexes, as you can have an array like `array(-1 => > 'foo')` > > And in my opinion one should not have differences in $string[x] and > $array[x] access. > That's an interesting notion, but I think in previous discussions the consensus was that array-index access and string offset were never going to be the same since non numeric array keys or multi-associative, etc don't translate to string offsets anyway. Can't remember how long/in regards to what this was, though!

« previous php.internals (#73718) next »