syntax error, unexpected token “;”

Description

The semi-colon marks the end of a command. They are needed in blocks, or sequences of commands.

In the first case, the semi-colon signals the end of the exit command, and PHP is still parsing the if condition.

In the second case, the semi-colon is understated by the closing PHP tag. The previous attribute #[A] requires a structure (class, interface, function…), which is not found.

Example

<?php

// 'if' needs a second closing ), but PHP keeps parsing it until the semi colon.
if ($d !== foo() {
    exit(1);
}

#[A()]
// This is an attribute, and it needs a structure to apply to.

?>

Solutions

  • Check previous opening and closing parenthesis, they might be unbalanced.