Skip to content

Property is never read, only written with null coalescing operator #6107

@ohtyap

Description

@ohtyap

Bug report

When accessing an optional class property with the null coalescing operator, phpstan does not recognize this as a reading operation, and the error Property XYZ is never read, only written. is reported.

These reported issues might be a similar (same?) problem, but not sure:
#6026
#3659

Code snippet that reproduces the problem

https://phpstan.org/r/2c837a4e-382c-4e83-af54-62716f0ccd94

I also added different approaches in the snippet below which are working. So it seems the issue is related to the null coalescing operator.

(The same behavior occurs with any object not only stdClass - just used it for simplicity in the playground)

Expected output

The class property is used - so the phpstan error should not be reported.

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

Yes - did also help me yesterday and the day before and ... 🙇

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions