Hi,
Rule php:S1172 (“Unused function parameters should be removed”) raises a false positive on a constructor parameter that uses PHP 8.1+ constructor property promotion when readonly is the only promotion modifier (no public / protected / private).
Minimal reproducer
<?php
class Foo
{
public function __construct(
readonly int $port,
) {
echo $this->port;
}
}
S1172 reports: Remove the unused function parameter “$port”.
$port is indeed unused, but it’s a promoted property and is read via $this->port in the constructor body.
Why this is a false positive
Per the PHP manual on constructor promotion:
Using a visibility modifier (public, protected or private) is the most likely way to apply property promotion, but any other single modifier (such as readonly) will have the same effect.
So readonly int $port (without an explicit visibility modifier) is valid promoted-property syntax; the visibility defaults to public, and the parameter is desugared to a real class property plus an assignment in the constructor.
Workarounds that confirm the diagnosis
Both of these silence the warning, which strongly suggests the check is detecting “promoted” by the presence of a visibility modifier rather than the broader set of promotion modifiers:
- Add an explicit visibility modifier:
public function __construct(private readonly int $port) { /* ... */ } - Reference the parameter directly instead of via
$this->:public function __construct(readonly int $port) { echo $port; }
Environment
- SonarQube Server v2025.5
- PHP version of analyzed code: 8.1+
Thanks!