syntax error, unexpected identifier “%s”, expecting “function” or “const”¶
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” or “const”
Solutions¶
Add a definition keyword before the name.
Fix the syntax and make a keyword appear at the beginning of the definition.
In more recent PHP versions, this error message is now syntax-error,-unexpected-identifier-“%s”,-expecting-“%s”.