New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect UninitializedProperty / PossiblyNullReference error due to buggy parent constructor detection #4540
Labels
Comments
I found these snippets: https://psalm.dev/r/6f670c1ffe<?php
class A
{
protected DateTimeImmutable $date;
public function __construct()
{
$this->date = new DateTimeImmutable();
}
}
class B extends A
{
}
class C extends B
{
public function __construct()
{
parent::__construct();
echo "I was instantiated at " . $this->date->format('c');
}
}
new C();
|
One workaround is to specify the constructor explicitly: https://psalm.dev/r/0851f087dc |
I found these snippets: https://psalm.dev/r/0851f087dc<?php
class A
{
protected DateTimeImmutable $date;
public function __construct()
{
$this->date = new DateTimeImmutable();
}
}
class B extends A
{
}
class C extends B
{
public function __construct()
{
A::__construct();
echo "I was instantiated at " . $this->date->format('c');
}
}
new C();
|
It's would be very unusual to see the code like that. |
danog
pushed a commit
to danog/psalm
that referenced
this issue
Jan 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the following example, I have three classes which extend from each other (
C
extendsB
extendsA
): https://psalm.dev/r/6f670c1ffe The middle class does not have a constructor but the other two do.Psalm doesn't seem to realize that when
C
's constructor callsparent::__construct()
it results inA
's constructor being called. As a result, Psalm thinks the property is never set, although it definitely is: https://3v4l.org/Q8lq3The text was updated successfully, but these errors were encountered: