RE: [PHP-DEV] Negative string offsets
| From: | Christian Stoller | Date: | Thu, 17 Apr 2014 13:11:55 +0000 |
| Subject: | RE: [PHP-DEV] Negative string offsets | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-73717@lists.php.net to get a copy of this message | ||
> 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.