PHP 以 "t"、"s"、"n" 结尾的命名空间奇怪文件夹

PHP Namespace oddity folders ending with "t","s","n"

我遇到一个有趣的问题,如果命名空间中的某个文件夹以 "t"、"s" 或 "n" 结尾,那么它后面有一个子文件夹,那么它不会解析。

例如:

namespace DDM\Components\Widget\List;

这导致:Parse error: syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING) in <...filepath...>

以前面提到的其他 2 个字母结尾的文件夹也会发生同样的情况。

我在 windows 系统上,但文件是从 Debian (jessie) 盒子提供的,运行 PHP 版本 5.6.27-0+deb8u1 通过 nginx 和PHP-FPM

更新

如果我尝试用 \ 作为整个命名空间的前缀,那么 phpstorm 不再将其识别为语法错误,但 php 编译器仍然会给出与上述相同的错误。

任何 "L" 名称子文件夹都有此结果

正如 Jay 所指出的,List 是一个 PHP 保留字,但是使用任何 "L" 文件夹名称都会导致不同的错误:

Fatal error: Undefined constant 'DDM\Components\Widget\Lists' 

如有任何建议,我们将不胜感激。

这是因为 List 是保留关键字,不允许使用保留关键字,即使在命名空间中也是如此。

PHP Reserved Keywords