Skip to content

False-positive in properties #12553

@SerafimArts

Description

@SerafimArts

Bug report

Simple example:

<?php

class HelloWorld
{
    public private(set) \DateTimeImmutable $createdAt {
        get {
            return $this->createdAt ??= new \DateTimeImmutable();
        }
    }
}

Actual sandbox false-positive:

  • Class HelloWorld has an uninitialized property $createdAt. Give it default value or assign it in the constructor.

Actual PHPStan 2.1.3 false-positive:

  • Property HelloWorld::$createdAt is not writable

Actual PHPStan, in principle, considers any properties where setters are absent to be read-only, although this is not the case.

Code snippet that reproduces the problem

https://phpstan.org/r/70b0264c-11e8-4c22-94ad-f6cfaff44092

Expected output

  • All OK

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