Re: Negative string offsets
| From: | Johannes Schlüter | Date: | Mon, 20 Jun 2011 15:36:48 +0000 |
| Subject: | Re: Negative string offsets | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53416@lists.php.net to get a copy of this message | ||
On Mon, 2011-06-20 at 16:31 +0200, Etienne Kneuss wrote:
> >> Negative string offsets is a wish and also an implementation of my running
> >> PHP version for long. It operates in the same fashion like substr() with
> >> negative offsets, but avoids the function call and is much smarter if one
> >> single character has to be extracted:
> Do you mean ArrayObject? ArrayAccess is the interface.
> Regardless, I don't believe it makes sense to change the semantics of
> those indexes for arrays, since arrays can define negative indexes.
> i.e. $a = array(-1 => "foo", 2 => "bar"); $a[-1] should really be
> "foo", and not "bar".
This clearly shows the inconsistency this brings. Maybe $var{$offset}
should be clearly deprecated for arrays and $var[$offset] for strings as
in PHP they work differently.
johannes