vimeo/psalm

False positive PropertyNotSetInConstructor

Aperta

#5630 aperta il 14 apr 2021

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

Metriche repository

Star
 (5369 stelle)
Metriche merge PR
 (Metriche PR in attesa)

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