syntax error, unexpected namespaced name “%s”, expecting “function”¶
Description¶
A namespaced name is an identifier with at least one backslash. The body of a class, enumeration, trait or interface does not use any namespaces, as it declares methods, constants and proeprties. There may be namespaced names in a use
declaration, but such expression starts with a keyword.
Example¶
<?php
class X {
A\B;
C\D($e);
}
?>
Solutions¶
Add the
use
keyword before the name to import a trait.Add the
function
keyword before the name to make it a method, although there should not be any\
in the method name.Add the
const
keyword before the name to make it a constant, although there should not be any\
in the constant name.Add the
#[
keyword before the name to make it an attribute.