vimeo/psalm

False positive PropertyNotSetInConstructor

Open

#5630 aperta il 14 apr 2021

Vedi su GitHub
 (21 commenti) (0 reazioni) (0 assegnatari)PHP (668 fork)batch import
Help wantedbugtraits

Metriche repository

Star
 (5369 star)
Metriche merge PR
 (Merge medio 3g 12h) (5 PR mergiate in 30 g)

Descrizione

<?php

trait CreatedAt {
    protected DateTimeImmutable $createdAt;

    private function onCreated(): void {
        $this->createdAt = new DateTimeImmutable();
    }
}

class Foo {
    use CreatedAt;

    public function __construct() {
    	$this->onCreated();
    }
}

class Bar extends Foo {}

Property $createdAt was initialized it Foo constructor. But psalm knows nothing about it in Bar.

https://psalm.dev/r/106a0483f7

Guida contributor