FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Return type detection using static issue "...should return static(Foo) but returns Foo" · Issue #10286 · phpstan/phpstan · GitHub

Return type detection using static issue "...should return static(Foo) but returns Foo" #10286

Description

Bug report

Accordint to PHPStan doc https://phpstan.org/writing-php-code/phpdocs-basics Using @return static along with the self native typehint means that the method returns a child class

As of 1.10.48 (not present on 1.10.47) return types at level 3 report an error like:
Method Foo::create() should return static(Foo) but returns Foo. using this example:

interface IFoo
{
	/** @return static */
	public static function create();
}

class Foo implements IFoo
{
	public static function create(): self
	{
		return new self();
	}
}

I don't think this is an error.
If it is an error in the code, how it could be solved?
If it is not an error, then it is a bug?

Thanks for PHPStan, it is geat!

Code snippet that reproduces the problem

https://phpstan.org/r/2eb3158b-0c10-4138-8e91-0daf17390e77

Expected output

The issue is reported incorrectly.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan is a great tool, you are helping us (PhpCfdi) to maintain libre high-quality tools for Mexican PHP developers. Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL