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 […] not found and could not be autoloaded #576

Closed
UFOMelkor opened this issue Nov 2, 2017 · 8 comments
Closed

Class […] not found and could not be autoloaded #576

UFOMelkor opened this issue Nov 2, 2017 · 8 comments
Labels
Milestone

Comments

@UFOMelkor
Copy link

Hey,

I've added phpstan to a package which has some dependencies to symfony, especially symfony/dependency-injection: ~3.3.
It does not depend on symfony/expression-language and does not use any class from there,
but the symfony/expression-language is an optional dependency for symfony/dependency-injection.

Short: symfony/dependency-injection is installed and used, symfony/expression-language not.
When I run phpstan I get

Class Symfony\Component\ExpressionLanguage\ExpressionLanguage not
found and could not be autoloaded.

(see Travis Build)

It looks like its analyzing the Symfony\Component\DependencyInjection\ContainerBuilder and fails about

    /**
     * @var ExpressionLanguage|null
     */
    private $expressionLanguage;

Anything I can do to avoid this error besides requiring symfony/expression-language as dev-dependency?

@ondrejmirtes ondrejmirtes added this to the 0.9 milestone Nov 2, 2017
@ondrejmirtes
Copy link
Member

ondrejmirtes commented Nov 2, 2017

Hi, thanks for the report. I will investigate this because it looks like the autoloading isn't necessary, the nonexistent class is not in your code.

@UFOMelkor
Copy link
Author

Thank you 👍
Let me know when I can do anything to help.

@ondrejmirtes
Copy link
Member

I see what the problem is now:

namespace Symfony\Component\DependencyInjection;

use Symfony\Component\ExpressionLanguage\ExpressionLanguage as BaseExpressionLanguage;

class ExpressionLanguage extends BaseExpressionLanguage
{
    //...
}

Autoloader is asked whether Symfony\Component\DependencyInjection\ ExpressionLanguage exists - autoloader says yes, because you have symfony/dependency-injection installed. So when Broker::hasClass() returns true, PHPStan sees no reason not to proceed and loads the class. But that fails, because the class that is extended Symfony\Component\ExpressionLanguage\ExpressionLanguage does not exist.

The reason why PHPStan is even interested in this class is because it creates all property reflections of a class when it's first loaded. I could remedy this problem by moving to a more lazy creation but I'm afraid of performance implications. I might try that soon but I'm not sure about the results.

ondrejmirtes added a commit that referenced this issue Nov 16, 2017
@ondrejmirtes
Copy link
Member

I realized that this problem does not longer exist on dev-master. So once you upgrade to 0.9 which will be out this month, you should be fine even without the optional dependency.

I added a test: acaac52 and made sure it fails on 0.8.5.

@ondrejmirtes
Copy link
Member

Oh god, I realized that the issue is still here but you have to construct a different phpDoc in order to surface it.

@ondrejmirtes ondrejmirtes reopened this Nov 16, 2017
@ondrejmirtes
Copy link
Member

Reproduced here: #601

@ondrejmirtes
Copy link
Member

Fixed for real: 8055761

@UFOMelkor
Copy link
Author

Thank you very much for your effort 👍

UFOMelkor added a commit to UFOMelkor/service-bus-symfony-bundle that referenced this issue Dec 7, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants