Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jkufner opened this issue Sep 18, 2019 · 8 comments · Fixed by phpstan/phpstan-src#1953
Closed
Labels
Milestone

Comments

@jkufner
Copy link

jkufner commented Sep 18, 2019

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.

@ondrejmirtes
Copy link
Member

Thanks. Proof that it works: https://3v4l.org/GH1v2

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 30, 2019
@staabm
Copy link
Contributor

staabm commented Aug 26, 2021

@phpstan-bot
Copy link
Contributor

@jkufner After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+5: Property Foo::$root is never written, only read.
 8: Access to private property $root of parent class Foo.
Full report
Line Error
5 Property Foo::$root is never written, only read.
8 Access to private property $root of parent class Foo.

@phpstan-bot
Copy link
Contributor

@jkufner After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-8: Access to private property $root of parent class Foo.
+8: Access to private property $root of parent class Foo.
+5: Property Foo::$root is never written, only read.
Full report
Line Error
8 Access to private property $root of parent class Foo.
5 Property Foo::$root is never written, only read.

@phpstan-bot
Copy link
Contributor

@jkufner After the latest push in 1.9.x, PHPStan now reports different result with your code snippet:

@@ @@
-8: Access to private property $root of parent class Foo.
+5: Property Foo::$root is never written, only read.
Full report
Line Error
5 Property Foo::$root is never written, only read.

@phpstan-bot
Copy link
Contributor

@jkufner After the latest push in 1.9.x, PHPStan now reports different result with your code snippet:

@@ @@
-8: Access to private property $root of parent class Foo.
+5: Property Foo::$root is never written, only read.
Full report
Line Error
5 Property Foo::$root is never written, only read.

@phpstan-bot
Copy link
Contributor

@jkufner After the latest push in 1.9.x, PHPStan now reports different result with your code snippet:

@@ @@
-8: Access to private property $root of parent class Foo.
+5: Property Foo::$root is never written, only read.
Full report
Line Error
5 Property Foo::$root is never written, only read.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants