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

False positive UndefinedClass in method_exists for trait #2124

Closed
TysonAndre opened this issue Sep 11, 2019 · 4 comments
Closed

False positive UndefinedClass in method_exists for trait #2124

TysonAndre opened this issue Sep 11, 2019 · 4 comments

Comments

@TysonAndre
Copy link
Contributor

<?php

trait MockTrait {
    public static $prop;
    public function someMethod() {
    }
}
// Observed: ERROR: UndefinedClass - src/test.php:7:26 - Class or interface MockTrait does not exist
// Expected: should not warn
// Output is true
var_export(method_exists('MockTrait', 'someMethod'));
@muglug muglug added the bug label Sep 11, 2019
@muglug muglug removed the bug label Sep 22, 2019
@muglug
Copy link
Collaborator

muglug commented Sep 22, 2019

Not a bug, this works: https://psalm.dev/r/e552e080cc

@muglug muglug closed this as completed Sep 22, 2019
@TysonAndre
Copy link
Contributor Author

I'm still seeing this error if MockTrait is declared in the same file below the usage of method_exists https://psalm.dev/r/1bcf6f4dc1

@muglug
Copy link
Collaborator

muglug commented Oct 18, 2019

What if you use a class constant? https://psalm.dev/r/f341d94eb3

@TysonAndre
Copy link
Contributor Author

It seems like my issue was caused by the fact that the autoloader didn't know how to autoload that trait. That trait was in psalm's configured list of directories, but autoloading required switching to the augmented autoloader used for unit tests.

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

No branches or pull requests

2 participants