php の予約語のキーワードは何の名前になら使えるのか

PHP 7 系で `new` や `for` などの予約語がメソッド名などに使えるようになっているのは知っていたけど、イマイチその対象と範囲が理解できていなかったので手を動かして確認してみた。

```
Query::new()->for('foo')->as('hoge')->if(42)->and('bar')->or('baz')->list()->echo();
```

みたいなやつ。

https://www.php.net/manual/ja/reserved.keywords.php

https://wiki.php.net/rfc/context_sensitive_lexer

https://github.com/php/php-src/pull/1221/

結論としては、マニュアルに書いてあるとおりで、「これらのキーワードを プロパティや定数の名前として使える」（クラスやインタフェースやトレイトや関数の名前には使えない）という理解で間違いなさそう。

だだし、明記されているとおり **class** はメソッドやプロパティの名前には使えない。

**default** はクラス名・インタフェース名・トレイト名にだけ使えて、関数の名前には使えないのがおもしろい。

|  | class | interface | trait | function | var | method | property |
|---|---|---|---|---|---|---|---|
| abstract | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| and | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| array | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| as | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| break | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| callable | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| case | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| catch | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| class | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ |
| clone | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| const | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| continue | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| declare | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| default | ok | ok | ok | ✘ | ok | ok | ok |
| die | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| do | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| echo | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| else | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| elseif | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| empty | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| enddeclare | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| endfor | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| endforeach | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| endif | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| endswitch | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| endwhile | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| eval | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| exit | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| extends | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| final | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| finally | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| for | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| foreach | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| function | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| global | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| goto | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| if | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| implements | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| include | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| include_once | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| instanceof | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| insteadof | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| interface | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| isset | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| list | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| namespace | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| new | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| or | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| print | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| private | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| protected | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| public | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| require | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| require_once | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| return | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| static | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| switch | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| throw | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| trait | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| try | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| unset | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| use | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| var | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| while | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| xor | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |
| yield | ✘ | ✘ | ✘ | ✘ | ok | ok | ok |

https://github.com/youhey/php-reserved-keywords