syntax error, unexpected token “protected”, expecting “{”

Description

protected and the other visibility options are only seen inside a class or CITE. They mark the start of their definition (property, constant, method), and can only be seen in the body of the CITE.

With an expected opening curly brace, this means the class signature was not finished with the opening curly brace.

Example

<?php

class X
    protected function foo() {}
}

?>

Solutions

  • Add the opening curly bracket between the class signature and its body.

  • Add the opening curly bracket between the interface signature and its body.

  • Add the opening curly bracket between the trait signature and its body.

  • Add the opening curly bracket between the enum signature and its body.