Re: Support negative indexes for arrays and strings
| From: | Rasmus Schultz | Date: | Fri, 31 Aug 2012 17:11:01 +0000 |
| Subject: | Re: Support negative indexes for arrays and strings | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62613@lists.php.net to get a copy of this message | ||
Yes, typo! sorry.
$array = array(1001, 1002, 1003, 1004);
$number = $array[-1]; // => 1004
$array[-1] = 1005;
$number = $array[-1]; // => ????
Looking at the resulting code, I would like to point out also that
it's extremely misleading... because $array[-1] references two
completely different elements depending on whether you're reading or
writing the value... unless $array[-1] = 1005 would actually overwrite
the last element in the array - in which case it gets even more
dangerous, as well as breaking backwards compatibility...
On Fri, Aug 31, 2012 at 9:24 AM, Ferenc Kovacs <tyra3l@gmail.com> wrote:
>
>
> On Fri, Aug 31, 2012 at 3:14 PM, Rasmus Schultz <rasmus@mindplay.dk> wrote:
>>
>> Having thought about this for a while, I think this is a bad idea - here's
>> why:
>>
>> $array = array(1001, 1002, 1003, 1004);
>>
>> $number = $array[-1]; // => 1004
>>
>> $number[-1] = 1005;
>>
>> $number = $array[-1]; // => ????
>>
>> Obviously, the last statement must return 1005, since otherwise that
>> value would be inaccessible.
>>
>
> maybe you wanted to write
> $array[-1] = 1005;
> instead of
> $number[-1] = 1005;
> ?
>
> otherwise I can't see the problem that you are mentioning.
> could you clarify?
>
> --
> Ferenc Kovács
> @Tyr43l - http://tyrael.hu