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

Description

This syntax error is related to the usage of PHP keyword in a namespace. Until PHP 8.0, the namespace could not use any such keyword, and produced a compilation error.

Example

<?php

namespace A\eval\B;

?>

Solutions

  • Upgrade to PHP 8.0 or more recent.

  • Rename the namespace to avoid using PHP keywords.