-
-
Notifications
You must be signed in to change notification settings - Fork 934
Closed
phpstan/phpstan-src
#1340Labels
Description
Bug report
Phpstan is not reporting uninitialized property from Trait. (tried on phpstan version 1.6.8)
7 Class Foo has an uninitialized property $id. Give it default value or assign it in the constructor.
8 Property Foo::$val is never read, only written.
$email is missing here...
Code snippet that reproduces the problem
parameters:
level: 8
checkUninitializedProperties: true// src/index.php
<?php declare(strict_types = 1);
require '../vendor/autoload.php';
class Foo {
public int $id;
private ?string $val = null;
use EmailTrait;
}
trait EmailTrait
{
protected string $email; // not initialized
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): void
{
$this->email = $email;
}
}
$foo = new Foo();
echo $foo->getEmail(); // error Typed property must not be accessed before initialization
echo $foo->id;