Syntax error, unexpected 'Interface' (T_INTERFACE), expecting identifier (T_STRING)

✔ Recommended Answer

My excuses, this is indeed documented behaviour, just not in the manual: see and

You may have found a corner case in PHP language parser. Interface in a PHP Keyword. But it isn't explicitly mentioned in the list of allowed/disallowed usages:

The following words cannot be used as constants, class names, or function names. They are, however, allowed as property, constant, and method names of classes, interfaces and traits, except that class may not be used as constant name.

These are valid:

use NotInterface\{    Parser\ZipFilenameParserInterface,    Query\UpdateLettersQueryInterface,};


use Interface\Parser\ZipFilenameParserInterface;use Interface\Query\UpdateLettersQueryInterface;


This is not:

use Interface\{    Parser\ZipFilenameParserInterface,    Query\UpdateLettersQueryInterface,};


Method #2

This error message typically occurs when you are trying to declare an interface, but you have not provided a name for the interface.

For example, consider the following code:

interface { public function myMethod(); }

This code will produce the following error message:

PHP Parse error: syntax error, unexpected 'Interface' (T_INTERFACE), expecting identifier (T_STRING) in /path/to/file.php on line X

To fix this error, you simply need to provide a name for the interface. For example:

interface MyInterface { public function myMethod(); }

By providing a name for the interface, you are specifying the identifier that is expected by the PHP parser, and the error message should no longer occur.


Most Popular

PhpStorm, return value is expected to be 'A', 'object' returned

Remove Unicode Zero Width Space PHP

Laravel file upload returns forbidden 403, file permission is 700 not 755