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

PhanAbstractStaticMethodCallInStatic Potentially calling an abstract static method #4150

Closed
westerp opened this issue Aug 17, 2020 · 2 comments
Labels

Comments

@westerp
Copy link

westerp commented Aug 17, 2020

Phan version 3.1.1, and dev-master

Valid PHP:

<?php

abstract class Base
{
    abstract protected static function getInstance();

    /**
     * @return static
     */
    public static function get()
    {
        return static::getInstance();
    }
}

class TestImpl
{
    protected static function getInstance()
    {
        return new TestImpl();
    }
}

// Example usage
$obj = TestImpl::get();

Reports:

Test.php:13 PhanAbstractStaticMethodCallInStatic Potentially calling an abstract static 
method \Test::getInstance() with static:: in static::getInstance() 
(the calling static method's class scope may be an abstract class)

Expected: no errors

@TysonAndre
Copy link
Member

This is by design, and was intended to be added in #3799

The issue is emitted because code that isn't analyzed can call Base::get() directly, and the only place where it makes sense to warn is in the implementation of get() itself, or abstract class OtherBase extends Base. (i.e. (the calling static method's class scope may be an abstract class))

@TysonAndre
Copy link
Member

It's recommended that you suppress the issue (either globally, or just for the method declaration in question) and document that the methods are only meant to be called on concrete classes

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