# ERROR: Unable to parse file PHP ENUMs

**URL:** <https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856>\
**Category:** SonarQube Server / Community Build\
**Tags:** php8, php\
**Created:** [January 22, 2022, 4:44pm UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856 "2022-01-22T16:44:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![LocalHeroPro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/localheropro/32/16639_2.png) [@LocalHeroPro](https://community.sonarsource.com/u/LocalHeroPro)\
**Post date:** [January 22, 2022, 4:44pm UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/1 "2022-01-22T16:44:39Z")

</div>

Template for a good bug report, formatted with [Markdown](https://commonmark.org/help/):

- versions used (SonarQube: Community Edition 9.1 (build 47736), Scanner: 4.6.2.2472, Plugin, and any relevant extension)
- steps to reproduce: run sonar-scanner on app/code using PHP 8.1 with Enums.

```auto
ERROR: Unable to parse file [file:///var/www/cpt.local/html/app/Enums/Export/Orientation.php] at line 7
ERROR: Parse error at line 7 column 8:

 1: <?php
 2: 
 3: namespace App\Enums\Export;
 4: 
 5: use App\Enums\Base;
 6: 
 7: enum Orientation: int
           ^
 8: {
 9: use Base;
10: 
11: case LANDSCAPE = 1;
12: case PORTRAIT = 2;
13: 
14: public const DEFAULT = self::LANDSCAPE;
15: 
16: /**
17: * @throws \Exception

ERROR: Unable to parse file [file:///var/www/cpt.local/html/app/Enums/File/Type.php] at line 7
ERROR: Parse error at line 7 column 6:

 1: <?php
 2: 
 3: namespace App\Enums\File;
 4: 
 5: use App\Enums\Base;
 6: 
 7: enum Type: int
         ^
 8: {
 9: use Base;
10: 
11: case INCOMING = 1;
12: case RESULTING = 2;
13: case ERROR = 3;
14: 
15: public const DEFAULT = self::INCOMING;
16: 
17: public function getName(): string

ERROR: Unable to parse file [file:///var/www/cpt.local/html/app/Enums/Export/Type.php] at line 7
ERROR: Parse error at line 7 column 6:

 1: <?php
 2: 
 3: namespace App\Enums\Export;
 4: 
 5: use App\Enums\Base;
 6: 
 7: enum Type: int
         ^
 8: {
 9: use Base;
10: 
11: case ORDERS = 1;
12: case ORDER_PRODUCTS = 2;
13: 
14: public const DEFAULT = self::ORDERS;
15: 
16: public function getName(): string
17: {

ERROR: Unable to parse file [file:///var/www/cpt.local/html/app/Enums/Export/Format.php] at line 7
ERROR: Parse error at line 7 column 6:

 1: <?php
 2: 
 3: namespace App\Enums\Export;
 4: 
 5: use App\Enums\Base;
 6: 
 7: enum Format: int
         ^
 8: {
 9: use Base;
10: 
11: case CSV = 1;
12: case ODS = 2;
13: case PDF = 3;
14: case XLSX = 4;
15: 
16: public const DEFAULT = self::XLSX;
17: 

```

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [January 23, 2022, 10:30am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/2 "2022-01-23T10:30:18Z")

</div>

Hey there.

PHP 8.1 syntax will become supported in SonarQube _v9.3_, which should be released at the end of this month.

---

<div class="post-metadata">

**Author:** ![LocalHeroPro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/localheropro/32/16639_2.png) [@LocalHeroPro](https://community.sonarsource.com/u/LocalHeroPro)\
**Post date:** [January 23, 2022, 10:45am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/3 "2022-01-23T10:45:12Z")

</div>

Did Sonar Team consider make some update to previous version of Sonar - eg.: 9.1/9.2 - to work with PHP 8.1? Or PHP 8.1 will start working from 9.3 Sonar version?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [January 23, 2022, 10:48am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/4 "2022-01-23T10:48:07Z")

</div>

PHP 8.1 will be supported from SonarQube _v9.3_. New language analysis features are exclusively supported in the newest versions of SonarQube, not backported.

---

<div class="post-metadata">

**Author:** ![LocalHeroPro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/localheropro/32/16639_2.png) [@LocalHeroPro](https://community.sonarsource.com/u/LocalHeroPro)\
**Post date:** [April 19, 2022, 5:36pm UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/5 "2022-04-19T17:36:11Z")

</div>

Right now I have SonarQube v9.4 and newest SonarScanner v4.7 and I still have same unsupported ENUMs in PHP 8.1.

---

<div class="post-metadata">

**Author:** ![Nils\_Werner](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nils_werner/32/14437_2.png) [@Nils\_Werner](https://community.sonarsource.com/u/Nils_Werner)\
**Post date:** [April 26, 2022, 9:26am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/7 "2022-04-26T09:26:14Z")

</div>

Hello @LocalHeroPro,

I’m not able to reproduce the problem with version 9.4 using the code snippet from your first post. Is it exactly this code that causes problems with the current version? Otherwise, can you provide us with another reproducer that constructs an enum that is not parsed properly?

Best,  
Nils

---

<div class="post-metadata">

**Author:** ![LocalHeroPro](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/localheropro/32/16639_2.png) [@LocalHeroPro](https://community.sonarsource.com/u/LocalHeroPro)\
**Post date:** [April 26, 2022, 9:47am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/8 "2022-04-26T09:47:12Z")

</div>

- Community Edition Version 9.4 (build 54424)
- SonarScanner 4.7.0.2747, Java 11.0.14.1 Eclipse Adoptium (64-bit), Linux 5.4.0-109-generic amd64

In that snippet you have two examples of errors with ENUMs.

```auto
//
INFO: Sensor PHP sensor [php]
INFO: Starting PHP symbol indexer
INFO: 395 source files to be analyzed
INFO: 395/395 source files have been analyzed
INFO: Starting PHP rules
INFO: 395 source files to be analyzed
ERROR: Unable to parse file [file:///var/www/cpt.local/html/app/Enums/OrderStatus.php] at line 9
ERROR: Parse error at line 9 column 10:

 1: <?php
 2: 
 3: namespace App\Enums;
 4: 
 5: enum OrderStatus: int
 6: {
 7: use Base;
 8: 
 9: case NEW = 1;
             ^
10: case PICKUP_IN_PERSON = 2;
11: case FOR_DISPATCH = 3;
12: case CANCELED = 4;
13: case ENDED = 5;
14: 
15: public function label(): string
16: {
17: return match ($this) {
18: self::NEW => 'new',
19: self::PICKUP_IN_PERSON => 'pickup in person',

ERROR: Unable to parse file [file:///var/www/cpt.local/html/app/Enums/TaskStatus.php] at line 7
ERROR: Parse error at line 7 column 10:

 1: <?php
 2: 
 3: namespace App\Enums;
 4: 
 5: enum TaskStatus: int
 6: {
 7: case NEW = 1;
             ^
 8: case IN_PROGRESS = 2;
 9: case ENDED_WITH_ERRORS = 3;
10: case ENDED_WITH_SUCCESS = 4;
11: 
12: public const DEFAULT = self::NEW;
13: 
14: public function label(): string
15: {
16: return match ($this) {
17: self::NEW => 'new',

INFO: 395/395 source files have been analyzed
INFO: Importing /var/www/cpt.local/html/phpunit-execution-result.xml
INFO: Importing /var/www/cpt.local/html/phpunit-coverage-result.xml
INFO: Sensor PHP sensor [php] (done) | time=13201ms
INFO: Sensor Analyzer for "php.ini" files [php]
INFO: Sensor Analyzer for "php.ini" files [php] (done) | time=3ms
INFO: Sensor Text Sensor [text]

//

```

---

<div class="post-metadata">

**Author:** ![Nils\_Werner](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/nils_werner/32/14437_2.png) [@Nils\_Werner](https://community.sonarsource.com/u/Nils_Werner)\
**Post date:** [April 26, 2022, 10:05am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/9 "2022-04-26T10:05:41Z")

</div>

This is a very helpful reproducer. The problem comes from the keyword `NEW` which leads to the parser error. I have created a [ticket](https://jira.sonarsource.com/browse/SONARPHP-1296) so that this error will be fixed as soon as possible. Thanks for your advice.

Best,

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [May 3, 2022, 10:06am UTC](https://community.sonarsource.com/t/error-unable-to-parse-file-php-enums/56856/10 "2022-05-03T10:06:38Z")

</div>

Closed on May 3, 2022, 10:06am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
