syntax error, unexpected fully qualified name “%s”, expecting “function” or “const”

Description

There should not be any fully qualified name inside the body of a class, enumeration, trait or interface. Names are used for methods or constants, or with the use expression, to import a trait.

Example

<?php

class X {
    \A;
}

?>

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.