syntax error, unexpected token “#[”, expecting “,” or “;”

Description

The #[ token marks the beginning of an attribute. The previous statement is either not finished with a semi-colon, or could be extended with another set of code and then finished with a semi-colon.

Example

<?php

// missing ; or ,
use A as B

#[MyAttribute]
class X {}

?>

Solutions

  • Finish the previous use statement, with a semi-colon.

  • Complete the previous use statement, and finish it with a semi-colon.