# Parse error on a parameter type that starts with Public\\ or Private\\

**URL:** <https://community.sonarsource.com/t/parse-error-on-a-parameter-type-that-starts-with-public-or-private/190829>\
**Category:** SonarQube Cloud\
**Tags:** php, coverage\
**Created:** [November 3, 2026, 7:08pm UTC](https://community.sonarsource.com/t/parse-error-on-a-parameter-type-that-starts-with-public-or-private/190829 "2026-11-03T19:08:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruslan\_Abelkharisov](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ruslan_abelkharisov/32/78134_2.png) [@Ruslan\_Abelkharisov](https://community.sonarsource.com/u/Ruslan_Abelkharisov)\
**Post date:** [November 3, 2026, 7:08pm UTC](https://community.sonarsource.com/t/parse-error-on-a-parameter-type-that-starts-with-public-or-private/190829/1 "2026-11-03T19:08:32Z")

</div>

## Product and version

- SonarQube Cloud, CI-based analysis.
- Scanner: `SonarSource/sonarqube-scan-action` v7.0.0 in GitHub Actions.
- PHP version of the project: 8.4.

## Problem

If the first segment of a parameter type is `Public`, `Private` or `Protected`, the analysis cannot parse the method. The scanner logs this warning and skips the whole file:

```auto
WARN Unable to parse file [file:///.../app/Http/Controllers/FooController.php] at line 244
WARN Cannot declare parameter with visibility outside of constructor

```

The code is valid PHP 8. Since PHP 8.0, PHP reads a namespaced name as one token (`T_NAME_QUALIFIED`). Thus `Private` in `Private\FooRepository` is a namespace segment, not a visibility modifier. `php -l` accepts the file.

## Minimal example

```php
<?php

namespace App\Repository\Private;

class FooRepository {}

namespace App\Http;

use App\Repository\Private;

class FooController
{
    public function list(Private\FooRepository $repository): void {}
}

```

Expected: the file is analyzed.  
Actual: “Unable to parse file … Cannot declare parameter with visibility outside of constructor”, and the file gets no issues, no duplication data and no coverage.

## Probable cause

In `php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java`, the `PARAMETER()` rule is:

```java
f.parameter(
  b.zeroOrMore(ATTRIBUTE_GROUP()),
  b.zeroOrMore(PROMOTION_MODIFIER()),
  b.optional(DECLARED_TYPE()),
  ...

```

`PROMOTION_MODIFIER()` matches `Private` first. The rest of the name, `\FooRepository`, then matches `DECLARED_TYPE()` as a fully qualified name. After that, `TreeFactory.throwOnParameterWithVisibility()` finds a parameter with visibility in a method that is not `__construct`, and it throws the error.

SONARPHP-1085 (commit e38ac40dd5, January 2023) fixed reserved words inside namespace names for `use` and `namespace` statements. The parameter type position still has the problem.

## Impact

Our code style imports repository namespaces as `use App\Repository\Public;` and `use App\Repository\Private;`, so that `Public\` or `Private\` stays visible at each call site. Because of this bug, the analysis skips most of our controllers: no issues, no duplication and no coverage for these files.

---

<div class="post-metadata">

**Author:** ![stefan.schott](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/stefan.schott/32/75689_2.png) [@stefan.schott](https://community.sonarsource.com/u/stefan.schott)\
**Post date:** [November 6, 2026, 11:13am UTC](https://community.sonarsource.com/t/parse-error-on-a-parameter-type-that-starts-with-public-or-private/190829/2 "2026-11-06T11:13:37Z")

</div>

Hi Ruslan,

Thanks for reporting the issue. We’ve [fixed the issue](https://github.com/SonarSource/sonar-php/pull/1865) and it shouldn’t be occurring in the next release.
