Chausser Chausser - 1 year ago 81
PHP Question

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

I am having an intersting issue where if one of the folders in the namespace ends in a "t", "s", or "n" then has a subfolder after it then it wont parse.


namespace DDM\Components\Widget\List;

This causes:
Parse error: syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING) in <...filepath...>

Same happens for folder ending with the other 2 letters previously mentioned.

I am on a windows system but the files are being served from a Debian (jessie) box, running PHP Version 5.6.27-0+deb8u1 through nginx and PHP-FPM


If I try prefixing the entire namespace with a
then phpstorm no longer recognizes it as a syntax error but the php compiler still gives the same error as above.

Any "L" name subfolder has this result

As pointed out by Jay
is a PHP reserved word, however using any "L" folder name results in a different error:

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

Any suggestions are appreciated.

Answer Source

This is because List is a reserved keyword and reserved keywords are not allowed, even in namespaces.

PHP Reserved Keywords

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download