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

Class order in the generated stubs file doesn't allow them to be loaded properly #1

Closed
zaantar opened this issue Mar 15, 2018 · 3 comments

Comments

@zaantar
Copy link

zaantar commented Mar 15, 2018

Hi there, first of all, let me say that this is an awesome tool that has saved us a lot of time. So, thanks. :)

However, we've run into some issues when trying to use generated WordPress stubs together with PHPStan to analyze a WordPress plugin we're developing.

PHPStan, probably unlike other static analysis tools out there, is a bit less "static" and needs to actually load the php files in order to work.

That is not possible because the generated stub file contains things like this:

class Subclass extends ParentClass {

}

class ParentClass {

}

We need the parent class to be defined first, otherwise a PHP error occurrs when loading the file.

@GiacoCorsiglia
Copy link
Owner

Hello! Glad to hear you've found a use for this. Can't believe I never tried to execute the generated stubs; I guess they worked for Psalm which was enough for me. I'll try to implement a fix this weekend.

Of interest, your example code actually works fine (though it demonstrated your point). You need 2 levels of inheritance, both declared in the wrong order, for PHP to complain:

class SubSubClass extends SubClass {}
class SubClass extends ParentClass {}
class ParentClass {}

Coincidentally, there was just a Reddit post related to this.

Anyway, thanks for reporting this issue!

GiacoCorsiglia added a commit to GiacoCorsiglia/wordpress-stubs that referenced this issue Mar 17, 2018
See: GiacoCorsiglia/php-stubs-generator#1
Also stops generating stubs for the default plugins.
@GiacoCorsiglia
Copy link
Owner

Hi @zaantar, I've released an updated version of the WordPress stubs which fixes this issue along with several others. You can now run php wordpress-stubs.php without any fatal errors; however, there are still quite a few notices or warnings due to the global variable declarations.

Could you let me know if this is enough for PHPStan? If not, one solution may be to initialize all stubbed global variables as null, though I could see static analysis tools complaining about this as well.

@zaantar
Copy link
Author

zaantar commented Mar 18, 2018

Thank you a lot, @GiacoCorsiglia! I will play with PHPStan a bit more and let you know about my findings.

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