Le 31/01/2016 23:14, Stanislav Malyshev a écrit :
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.


Yes, authorizing array-related '[]' syntax on strings may look fine at first sight, but it only brings some unwanted ambiguity for no real benefit. And ambiguity increases with the support of negative string offsets.

So, I just added a chapter to the RFC, saying that documentation would be modified to recommend using the '{}' syntax for string offsets.

Regards

François

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to