vscode-intelephense
vscode-intelephense copied to clipboard
Support for Interface/Trait return self type
Describe the bug I suppose this is related to issue 1714, which was fixed recently. We have a similar problem, but are also using an interface. In this case the problem still persists.
To Reproduce
<?php
interface TestInterface
{
public function test(): self;
}
trait TestTrait
{
public function test(): self
{
return $this;
}
}
class TestClass implements TestInterface
{
use TestTrait;
public function save(): void
{
}
}
$test = new TestClass();
$test->test()
->save()
;
Screenshots
Platform and version Using Intelephense v1.10.2
This is how you can get rid of the error
<?php
declare(strict_types=1);
interface TestInterface
{
public function test(): static;
}
trait TestTrait
{
final public function test(): static
{
return $this;
}
}
final class TestClass implements TestInterface
{
use TestTrait;
public function save(): void
{
}
}
$test = new TestClass();
$test->test()
->save();
Thanks for your reply. Unfortunately marking affected classes as final is not an option in all cases. I still think this is a bug.