Visibility keyword in class constructor causes a parse error

Hi, according to the following ERROR: Unable to parse file PHP ENUMs SonarQube 9.3 should support PHP 8.1. I have upgraded but still are encountering issues.

Using SonarQube Version 9.4 (build 54424) and sonar-scanner-cli 4.7.0.

The error report states:

ERROR: Unable to parse file [file:///builds/xxxx/Configuration/Internationalization/I18nConfig.php] at line 12
ERROR: Parse error at line 12 column 42:
 2: declare(strict_types=1);
 4: namespace XX\XX\Configuration\Internationalization;
 6: class I18nConfig
 7: {
 8:     /**
 9:      * @param string        $defaultLocale    - Default locale of the installation
10:      * @param array<string> $supportedLocales - Supported locales of the installation
11:      */
12:     public function __construct(readonly public string $defaultLocale, readonly public array $supportedLocales)
13:     {
14:     }
15: }

Seems that the readonly keyword is tripping SonarQube up. Is this a bug or do I need to upgrade something?


Hello @Martin_Melka,

Sorry for the late response. Indeed, there is a parsing error in our parser. The problem is the order of characteristic keywords of the promoted properties. The code public readonly string $defaultLocale will not lead to a parsing error. However, we have to adapt our parser because different orders are also allowed. I’ve created a ticket to tackle this problem. Thank you for raising this point.


1 Like