Re: [RFC] Generalize support of negative string offsets
| From: | Nikita Popov | Date: | Mon, 01 Feb 2016 17:34:32 +0000 |
| Subject: | Re: [RFC] Generalize support of negative string offsets | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91048@lists.php.net to get a copy of this message | ||
On Sun, Jan 31, 2016 at 11:14 PM, Stanislav Malyshev <smalyshev@gmail.com>
wrote:
> Hi!
>
> > The only concern I have is that support of negative indexing will break
> > symmetry with (proper) arrays, where we cannot support negative indexing.
>
> I think that was the main source of objections to this proposal in the
> past. However, as one might say, string offsets are already not
> symmetrical to array offsets - e.g. you can do $array["foo"] but not
> $string["foo"].
>
> > However this is unlikely to be a significant issue. (I do however play
> with
> > the thought of reutilizing the obsolete {} indexing syntax to act as
> offset
> > indexing instead.)
>
> I think it may be a good idea to start recommending using {} for string
> offsets and [] for arrays. While both syntaxes may work for strings, the
> intent (and expected handling of negatives, in this case) is much
> clearer when different syntax is used.
I strongly disagree with this. $str[$offset] is well-recognized, generally
understood syntax that does not require familiarity with language
peculiarities. $str{$offset} might be clear to a Perl programmer, but to
anyone else this is just guesswork, with a typo being a reasonable
assumption.
We should be deprecating this alternative syntax instead of recommending
its use. I was under the impression that we *were* already discouraging its
use and it has already been temporarily deprecated.
Nikita