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

Fix false positives about unreferenced class elements in subclasses for static:: (constants, methods, properties) #3803

Open
TysonAndre opened this issue Mar 12, 2020 · 0 comments
Labels
enhancement This improves the quality of Phan's analysis of a codebase

Comments

@TysonAndre
Copy link
Member

Reported on gitter today

class A {
  public function foo() {
    return static::SOME_CONST;
  }
}

class B extends A {
  protected const SOME_CONST = 'hello, world';
}

Expected: PhanUndeclaredConstantOfClass is emitted, because (new A())->foo() (and so on) can be called.
Observed: PhanUnreferencedProtectedClassConstant and PhanUndeclaredConstantOfClass is emitted

This is causing PhanUnreferencedProtectedClassConstant for B::SOME_CONST. Shouldn't phan be able to see the usage in A? using 2.5.0 (and 2.6.1-dev)

Currently, Phan can't track this reference, because it only tracks references to elements that exist

Phan could track references to properties, methods, and class constants that don't exist separately from those that do exist, so that the reference to static::SOME_CONST, static::$some_prop, and static::someMethod() can be properly recorded.

Note that Phan already warns about the constant not existing in the base class

@TysonAndre TysonAndre added the enhancement This improves the quality of Phan's analysis of a codebase label Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This improves the quality of Phan's analysis of a codebase
Projects
None yet
Development

No branches or pull requests

1 participant