Skip to content

False positive: Access to private property $root of parent class Foo. #2435

@jkufner

Description

@jkufner

Bug report

Accessing private property of inherited class from parent class (where the property is defined) is valid, but PHPStan does not like it.

Code snippet that reproduces the problem

https://phpstan.org/r/2c1e2424-3b4d-4a31-aca7-0e8c74633a86

<?php

class Foo {
	/** @var Bar|null */
	private $root;
	
	public function checkRoot(): bool {
		return $this->root->root !== null;
	}
}

class Bar extends Foo {
}
+--------------------------------------------------------------+
| Line | test.php                                              |
+--------------------------------------------------------------+
| 8    | Access to private property $root of parent class Foo. |
+--------------------------------------------------------------+

Expected output

The code is fine. PHPStan should be quiet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions