Hi,

On Mon, Jun 20, 2011 at 14:05, Derick Rethans <der...@php.net> wrote:
> On Mon, 20 Jun 2011, Robert Eisele 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:
>>
>> $str = "Hallo";
>>
>> $str[0] == "H"
>> $str[-1] == "o";
>>
>> If -6 is used as offset, the old warning is displayed because it's the first
>> undefined negative offset.
>>
>> The same thing for setting:
>>
>> $str[-1] = '0';
>> $str[-4] = "4";
>>
>> will result in "H4ll0"
>>
>> Would be glad to see this in 5.4
>
> Sounds like a good addition to me! For ArrayAccess, would this calculate
> the "correct" index so that current implementations of ArrayAccess don't
> have to be changed?

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 looks useful for strings though!

>
> cheers,
> Derick
>
> --
> http://derickrethans.nl | http://xdebug.org
> Like Xdebug? Consider a donation: http://xdebug.org/donate.php
> twitter: @derickr and @xdebug
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Etienne Kneuss
http://www.colder.ch

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to