syntax error, unexpected identifier “%s”, expecting “,” or “;”

Description

This error is not related to the upcoming identifier, but to the previous delimiters. In both cases of the illustration, a string was started, with single or double quotes: yet, inside these strings, there was another set of the same delimiter. The parser could not differentiate between the two usages, and exited the string.

Example

<?php

// missing a '
echo '<a href='https://www.exakat.io'>Exakat.io</a>';

// missing a "
echo "<a href="https://www.exakat.io">Exakat.io</a>";

// missing as between identifier
use OpenApi\Attributesas OA;

?>

Solutions

  • Escape quotes inside a string, when they are used as delimiter.

  • Use the other quotes inside the string: if single quotes are used as delimiters, use double quotes in it.

  • Switch to the heredoc syntax, to simplify the syntax for both quotes.

  • Add the missing as, between the two identifiers, in a use instruction.