Re: Re: Support negative indexes for arrays and strings
| From: | Jannik Zschiesche | Date: | Mon, 03 Sep 2012 07:37:41 +0000 |
| Subject: | Re: Re: Support negative indexes for arrays and strings | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62706@lists.php.net to get a copy of this message | ||
Am Sonntag, 2. September 2012 um 02:43 schrieb slevy1@pipeline.com:
> The idea was originally proposed by Marc Easen who created a patch and asked for help with
> putting together an RFC. I have yet to see a formal proposal but on the list Easen modified his idea
> so that it should apply to strings alone. With that in mind, would it really cause problems to have
> code like this:
>
> $string = "Roses are red";
> $string[-3] = "R"; // modifying $string[10]
> echo $string; // Roses are Red
>
> The negative indexing provides a pleasurable way to easily access part of a string; it's
> simple and should be fast, too.
>
> I think Easen's proposal is laudatory and I for one would like to see it happen for PHP
> and provide users with more ease and satisfaction in working with the language.
>
> SL
Hi,
as I understood, a lot of people seem to have problems with this proposal, since arrays and strings
could (and maybe should) behave the same.
The main problem arises from the ambiguity for $array[-1] for arrays.
But this is easily solvable: just introduce a slice operator.
$array[:-1] and the ambiguity is gone.
--
Cheers
Jannik Zschiesche