Skip to content

@property Annotations on Non-Public Properties #13725

@kayw-geek

Description

@kayw-geek

Bug report

Problem:

PHPStan's @Property annotation correctly narrows the type for public properties, but fails to apply the same narrowing for protected or private properties.

Actual Behavior:

  • Public properties: The @property int $a annotation successfully narrows int|string $a to int
  • Protected/Private properties: The @property int $a annotation is ignored, and PHPStan infers the type as int|string

Code snippet that reproduces the problem

https://phpstan.org/r/c354ca2f-f42a-4194-99b1-f43aed7cd1e7

Expected output

The @Property annotation should narrow the property type regardless of the property's visibility (public, protected, or private).

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