Skip to content
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

PHP 8 static return type problem #5070

Closed
vudaltsov opened this issue Jan 20, 2021 · 1 comment
Closed

PHP 8 static return type problem #5070

vudaltsov opened this issue Jan 20, 2021 · 1 comment
Labels

Comments

@vudaltsov
Copy link
Contributor

It works with the phpdoc, but does not work with type declaration.

https://psalm.dev/r/4096286383

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/4096286383
<?php

abstract class A
{
    final private function __construct() {}
    
    final protected static function create1(): static
    {
        return new static();
    }
    
    /** @return static */
    final protected static function create2()
    {
        return new static();
    }
}

final class B extends A
{
	public static function doCretate1(): self
    {
    	return self::create1();
    }
    
	public static function doCretate2(): self
    {
    	return self::create2();
    }
}
Psalm output (using commit c912b6c):

INFO: LessSpecificReturnStatement - 23:13 - The type 'A&static' is more general than the declared return type 'B' for B::doCretate1

INFO: MoreSpecificReturnType - 21:39 - The declared return type 'B' for B::doCretate1 is more specific than the inferred return type 'A&static'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants