Re: Negative string offsets
| From: | Johannes Schlüter | Date: | Mon, 20 Jun 2011 21:36:12 +0000 |
| Subject: | Re: Negative string offsets | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53452@lists.php.net to get a copy of this message | ||
On Mon, 20 Jun 2011 18:27:48 +0200, Robert Eisele <robert@xarg.org> wrote:
> 2011/6/20 Johannes Schlüter <johannes@schlueters.de>
>> Yes. So having this in the current form accepted means that
>>
>> $a[-1];
>>
>> can have two meanings:
>>
>> 1) Get the last item (byte in a string)
>> 2) Get item
-1 (in an array)
>>
>
> Yes, sure. But if this feature is documented well, I can't see any
> problems with this, especially if the trend goes towards a more
> typed language where the user knows about the used data-type.
I consider having exact same semantics for two quite different operations
bad.
And I don't buy the "more typed language" argument.
What does
echo my_cool_function()[-1];
do?
>> Which are to different things.
>>
>> Currently we treat
>>
>> $a{$o} and $a[$o]
>>
>> as equal. My suggestion was to split this up to avoid the conflict from
>> above. I didn't suggest adding support for $a[-1] as last element for
>> arrays, I know quite well why this won't make sense.
>>
>
> I know about the equality of the two bracket forms. But I read somewhere
> that
> the trend goes towards [] - and maybe it was something from you.
There's no clear trend on this. It's a back and forth. Always depends on
the features we think about.
johannes