Skip to content

2.1.8 introduced false positive on protected access #13123

@jtojnar

Description

@jtojnar

Bug report

In PHP, for better or worse, visibility is class-wide, not object-wide. So any object A can access any protected property defined in any of ancestors or the A class on any object B that shares those classes in ancestry, even though the objects might be distinct.

In PHPStan 2.1.7 and earlier, PHPStan did not complain about such property access but 2.1.8 started to find them objectionable.

Code snippet that reproduces the problem

https://phpstan.org/r/f26c18dc-3de1-406a-a779-f446d21a0b08

Expected output

No error.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions