-
-
Notifications
You must be signed in to change notification settings - Fork 921
[PoC] Broker: Handle fatal errors when autoloading unknown classes/interfaces/traits #255
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
Conversation
I really don't get it - how is it supposed to work? |
Imagine you have a class Foo that extends class Bar. Class Foo exists and is known to at least one autoloader (i.e. Composer), but Bar does not. <?php
class Foo extends Bar {} Now, what happens when we attempt to instantiate Foo in our code:
What this PR does is:
|
Looks like a good idea. I'll try it on symfony. FYI, last time it died on 6 or 7 files, and I had to "fix" them manually for PHPStan to be able to complete the analysis
|
Symfony will fail because of other fatal errors, like class extending itself. You should probably exclude such files? |
There is still this problem with Symfony, but everything else passed!
because of (already mentioned) namespace Symfony\Component\VarDumper\Tests\Fixtures;
class NotLoadableClass extends NotLoadableClass
{
} with master, it dies here already
|
Btw, I haven't found a way to exclude a file from beeing loaded by PHPStan, only how to exclude it from the results. Guessing this is not implemented yet? |
ecafda3
to
0d0cb2b
Compare
@fprochazka There's a way how to exclude a file from analysis using |
I now understand @Majkl578's solution, but as @fprochazka pointed out, it only helps with a narrow issue of a referenced class not being found. It doesn't help with a lot of other issues, as non-abstract class having abstract methods, extending an interface in a class etc... Maybe a better approach (and all fatal errors encompassing) would be to implement a custom error handler that, although still exiting PHPStan prematurely, would at least clean the memory limit file to prevent the confusing message on the next run? |
I successfully tested this PR to prevent phpstan from dying when PHP Fatal Error for class not found occurs. It would be great if phpstan is tolerant to any PHP Fatal Errors and turn them to validation error in the report instead of dying. Note that most (if not all) real-life project that had not used a static code analyzer yet are far from perfect. Thus analyzing their code would produce lots of fatal errors. It is really discouraging to spend hours, if not days, in excluding files from analysis in order to get some initial report. |
OK, good to hear that. I'm considering to merge this but I'd really like a test case demonstrating this behaviour. @Majkl578 Can you try to add it in |
Merged with added testcase: 95af8d9 Thanks! |
Cool! And sorry, didn't get to it earlier. :/ |
Possible fix for #168 & #159. This could be completely wrong or broken.
Note that this doesn't handle other fatal errors, like:
or
Those would have to be checked on different level (parser?). This targets solely autoload failures.