syntax error, unexpected identifier “%s”, expecting “function”
Description
PHP identified a name in the body of a class, although it was not preceded by a keyword.
The error may suggest function, but any definition keyword will do: private, protected, public, var, const, function, use.
Example
<?php
class X {
publicfunction foo() {}
}
?>
Literal Examples
- syntax error, unexpected identifier “publicfunction”, expecting “function”
Alternatives
- Add a definition keyword before the name.
- Fix the syntax and make a keyword appear at the beginning of the definition.
In previous PHP versions, this error message used to be :ref:syntax-error,-unexpected-identifier-"%s",-expecting-"function"-or-"const".