-
-
Notifications
You must be signed in to change notification settings - Fork 947
Unsafe usage of new static() when constructor is defined in a parent class #6007
Copy link
Copy link
Closed
phpstan/phpstan-src
#1395Labels
Milestone
Description
Bug report
When a class implements an interface which defines a constructor but that constructor is defined in the class' parent, PHPStan reports a Unsafe usage of new static() error.
Code snippet that reproduces the problem
https://phpstan.org/r/77e24aff-9e5b-487e-97b6-d5fa1d95864a
<?php
interface FooInterface
{
public function __construct();
}
class VendorFoo {
public function __construct() {}
}
class Foo extends VendorFoo implements FooInterface
{
static function build():static {
return new static();
}
}When the child class also defines the constructor no error is reported:
https://phpstan.org/r/e54ff651-0397-4910-a5fb-534705ccddd5
Expected output
No error should be reported.
Did PHPStan help you today? Did it make you happy in any way?
Yes, it did find valid bugs 👍😅
Reactions are currently unavailable