On Thu, Sep 12, 2013 at 10:44 PM, Johannes Schlüter
<johan...@schlueters.de>wrote:

> I often stumbled over the annoyance of this limitation and I know many
> users want it, I'm not convinced about adding it, though.
>
> One reason is the "where (easily) possible" part. Right now we have a
> simple rule "keywords can't be reused". This is being changed to "this
> and that keyword can be used her and there." I don't believe this is
> good.
>
> Secondly I'm among the people who read tons of "bad" code and I'm sure
> people will abuse this and we will find code like this:
>
>     <?php
>     namespace network;
>     function if($which) {
>         // ... some logic ...
>             return "eth0";
>      }
>      // ... somewhere else in the namespace ...
>      if($condition);
>      ?>
>
> This can hide subtile typos or coding errors. Also look at currently
> valid PHP code like this:
>
>     <?php
>     function while() {}
>     $condition = true;
>     while ($condition)
>     ?>
>
> and while reading this mind that an ; in front of an ?> is optional, so
> will this call a function and exit or be stuck in an infinite loop?
>
> I'm sure one could construct other such cases.
>
> I'm more open about allowing such identifiers as method names only, as
> those are prefixed in some way ($object-> or someClass:: ) but even
> there I tend to consider the consistency between function and method
> names more important than this flexibility.
>

I tend to agree with Johannes. Supporting different sets of keywords in
different locations is pretty confusing. Imho we should add this kind of
support only in places where a) we can support all keywords and b) it is
unlikely that supporting keywords there will cause issues in the future.

One such case are method names. Methods with keyword names are currently
callable using $foo->array(), because the identifier after
T_OBJECT_OPERATOR is always a T_STRING. But while you can call them, it is
currently not possible to define them as real methods. Instead you need to
forward them via __call magic, which is rather ugly. Internal classes on
the other hand can and do define methods with reserved-keyword names. E.g.
there is a Generator::throw() method.

Nikita

Reply via email to