On Thu, Jun 18, 2020 at 8:44 AM Claude Pache <claude.pache@gmail.com> wrote:
> Hi,
>
> The following part of the proposal is problematic: Allow keywords in
> definition of classes, functions, const, etc.
>
> class KEYWORD {}interface KEYWORD {}trait KEYWORD {}function KEYWORD() {}const KEYWORD = 0;use Foo as KEYWORD;
>
> Under your proposal, the following code will compile without notice, but
> will have a different behaviour from what the programmer intended:
>
> ```php
> class Int { }
>
This part will still produce an error: "int" is not a reserved keyword, but
it is a reserved class name, and handled by a different mechanism.
const PRINT = 2;
> const YIELD = 3;
>
> function foo(Int $b) {
> return PRINT + YIELD;
> }
> ```
>
Yes, this is the tradeoff :) We trade the ability to use reserved keywords
in controlled situations, with potential confusion for cases like these.
If it is important to allow to define classes, etc. with a keyword as name,
> I suggest to force the programmer to say explicitly “Yes, it is really what
> I want”. For example, something like the following:
>
> ```php
> class namespace\Int { }
>
> const namespace\PRINT = 2;
> ```
>
This syntax doesn't make much sense to me. If we go down that line, I'd
suggest something along the lines of Rust's "raw identifier" concept, which
would allow you to write "const r#PRINT = 2" and "echo r#PRINT". This
syntax would work everywhere identifiers are accepted, e.g. the "namespace
iter\fn" would become "namespace iter\r#fn".
The disadvantage of this approach is that it is not backwards compatible
with PHP 7 and requires more active code change. E.g. the iter\fn example
would "just work" under this RFC, while this approach would require
rewriting the code.
Nikita
Another point which is problematic, is to allow `namespace` as a namespace