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.
- SonarQube Scanner 4.2.0.1873
- Potential workaround: None
- See RFC: https://wiki.php.net/rfc/typed_properties_v2
Error:
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);
3:
4: final class Car
5: {
6: /**
7: * @var string|null $color
8: */
9: public ?string $color = null;
^
10:
11: /**
12: * @var int $speed
13: * @var int $doors
14: * @var int $wheels
15: */
16: private int $speed = 0, $doors, $wheels;
17:
18: /**
19: * @var bool $working
Example File:
<?php
declare(strict_types=1);
// 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;
}
}