Re: Support negative indexes for arrays and strings
| From: | Richard Lynch | Date: | Mon, 11 Jun 2012 18:34:21 +0000 |
| Subject: | Re: Support negative indexes for arrays and strings | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-60790@lists.php.net to get a copy of this message | ||
On Mon, June 4, 2012 2:08 pm, Marc Easen wrote:
> I have submitted a patch to support negative indexs in strings, as per
> the conversation adding them to arrays could possibly detract from the
> syntactical sugar they are indented to be.
>
> In summary:
>
> An alternative to:
> $var = 'abc';
> echo $var[strlen($var) - 1];
>
> Can be:
> $var = 'abc';
> echo $var[-1];
This seems simple enough for a hard-coded -1, but...
Would $var[-2] be strlen($var) - 2 and so on?
And then one would expect some rather complex logic to compute -N for
$var[-N]
At that point, this becomes a pretty big WTF, imho.
I've never honestly felt it to be a big burden to use strlen($var) -
1, so I don't really see the point, at least for me.
--
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE