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 https://stackoverflow.com/a/75887334/13508 and https://wiki.php.net/rfc/namespaced_names_as_token
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,};
Source: stackoverflow.com
Answered By: Álvaro González
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:
phpinterface {
public function myMethod();
}
This code will produce the following error message:
luaPHP 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:
phpinterface 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.
Comments
Post a Comment