Sonar-scanner unable to parse files using PHP 7.4 property type feature

Sonar Scanner has a parsing exception on PHP files making use of the new PHP 7.4 feature: Typed Properties. PHP 7.4 is currently on RC4 and is scheduled for GA on November 28th.


ERROR: Unable to parse file [file:///src/Car.php] at line 9
ERROR: Parse error at line 9 column 12:

 1: <?php
 2: declare(strict_types=1);
 4: final class Car
 5: {
 6:     /**
 7:      * @var string|null $color
 8:      */
 9:     public ?string $color = null;
11:     /**
12:      * @var int $speed
13:      * @var int $doors
14:      * @var int $wheels
15:      */
16:     private int $speed = 0, $doors, $wheels;
18:     /**
19:      * @var bool $working

Example File:

// Car.php

final class Car
     * @var string|null $color
    public ?string $color = null;

     * @var int $speed
     * @var int $doors
     * @var int $wheels
    private int $speed = 0, $doors, $wheels;

     * @var bool $working
    private bool $working;

     * @var string $make
    var string $make = 'Toyota';

     * Car constructor.
     * @param string   $color
     * @param int      $speed
     * @param int|null $doors
     * @param int      $wheels
     * @param bool     $working
    public function __construct(string $color, int $speed, ?int $doors, int $wheels, bool $working=true)
        $this->color = $color;
        $this->speed = $speed;
        $this->doors = $doors;
        $this->wheels = $wheels;
        $this->working = $working;

Indeed, our PHP analyzer doesn’t support PHP 7.4 for the moment.
I created SONARPHP-942 to track support for typed properties.
Thanks for the feedback!

Sorry for bothering but even on version SonarScanner I’m having an issues with parsing files with typed properties like:

protected array $values = [];
private LoggerInterface $logger;

The version of SonarScanner is not relevant here.
You should check the version of sonar-php-plugin.
The support of types properties was added in version 3.3 of sonar-php-plugin.

@pynicolas I am running into this issue running on an old version of SonarQube - Community Edition
Version 7.6 (build 21501).
Our PHP version is PHP 7.4.14 and I checked, but can you tell me what is the minimum SonarQube version I should use to support PHP 7.4?

Hey @alabatarseh,

According to the versions matrix at least SonarQube 7.9 is required to have version 3.3 of the PHP Analyzer (which, as per the previous post, added support for property types).

If you are going to upgrade anyway, we strongly recommend to update to at least the latest LTS version (8.9) :slight_smile:

Thank you @Karim_El_Ouerghemmi . Another question, please. If we upgrade to SonarQube 7.9 do we loose “Branch Analysis” feature and GitLab support? I am looking at this features comparison

Hey @alabatarseh,

Built-in support for branch analysis and GitLab integration are only available starting from the developer edition, yes.

As far as I know, they were never available in the community edition. So, you might be using a third-party community plugin currently.

In any case, before upgrading, make sure to backup everything, and to follow this guide: Upgrade the Server | SonarQube Docs .

In case you have other questions about the upgrading process or feature availability, please open a new dedicated thread.