On 20 March 2015 01:28:53 GMT, Alex Bowers <bowersb...@gmail.com> wrote:
>I'm not sure what you mean by "something that happens nowhere else" PHP
>has
>> syntax for all sorts of things, using all sorts of symbols. Your own
>> suggestion uses the : symbol in a place where it currently can't
>exist.
>
>
>What I mean by 'symbol' here, is a prefix to tell it what the context
>of
>its use is; in this case, it is the declaration that we are requiring
>the
>index not the key. As far as I'm aware, and can think of at the moment,
>PHP
>has nothing like a hinter symbol.
>
>The only purpose of this symbol is to tell the user that it is indexes
>not
>keys.

The @ symbol in my examples is not a special marker that is meaningful on its 
own; the parser wouldn't even see it as a separate token. The syntax for key 
access is $array[$key], the syntax for positional access would be 
$array[@$position]; chosen to look similar, but one is not a special case of 
the other.

The syntax needn't be just an extra character, we could invent something else, 
like $array[[$position]], or $array@($position), though I can't think of 
anything I like.

Similarly, your suggested slice syntax is chosen to look similar to key access, 
and to the same feature in other languages, but since it doesn't exist yet, we 
can make up whatever parser rules we want.


>Maybe there should be a symbol to declare that, but i'm not sure. Will
>appreciate more comments on this.
>
>If we go the direction of using a symbol, what should be the outcome of
>the
>symbol missing? fatal error, or to try to slice based on the keys?

The symbol isn't something that can be missing, it's just part of the syntax, 
so this is like saying "what should we do if the closing ] is missing?" The 
answer is, nothing, it's undefined syntax, so it's a parse error.

You could implement slicing on keys, and if you did so, [x:y] would be the 
obvious syntax to use, but as you've said of negative positions, let's keep to 
one feature at a time.

Regards,
-- 
Rowan Collins
[IMSoP]


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

Reply via email to