vimeo/psalm

False positive PropertyNotSetInConstructor

Open

#5.630 aberto em 14 de abr. de 2021

Ver no GitHub
 (21 comments) (0 reactions) (0 assignees)PHP (668 forks)batch import
Help wantedbugtraits

Métricas do repositório

Stars
 (5.369 stars)
Métricas de merge de PR
 (Mesclagem média 3d 12h) (5 fundiu PRs em 30d)

Description

<?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

Guia do colaborador