Parse error on reserved keyword in namespace with PHP 8.1


The scanner can’t parse files where a PHP reserved keyword is used in the namespace (in my case it is Trait).

The same issue has been already reported with previous version of SonarQube/scanner:

I tried the latest version of SonarQube hoping the issue was resovled

  • SonarQube
  • SonarScanner

but unfortunately the issue is still here:

ERROR: Unable to parse file [file:///builds/htdocs/src/Infrastructure/Database/Entity/Budget.php] at line 9
ERROR: Parse error at line 9 column 40:
 1: <?php
 3: namespace App\Infrastructure\Database\Entity;
 5: use DateTimeInterface;
 6: use Doctrine\Common\Collections\ArrayCollection;
 7: use Doctrine\Common\Collections\Collection;
 8: use Doctrine\ORM\Mapping as ORM;
 9: use App\Infrastructure\Database\Entity\Trait\TimestampableTrait;

We are using traits a lot, so a large portion of our code base isn’t scanned at all.

With this error, it would be safer to say that SonarQube’s support for PHP 8 is not complete.


Hi @sschawohl

and welcome to the community. We are aware of this problem and will solve it soon. The related ticket is SONARPHP-1085. Thanks for your report.


1 Like