-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Throw better exception when missing use-statement #34239
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
Is this really the message or is it: - Class "App\Bar\StartpageController" used for service "App\Bar\StartpageController" cannot be found.
+ Class "App\Bar\MyBaseController" used for service "App\Bar\StartpageController" cannot be found. |
Yes, it is really correct. I did not make a typo. That is why the error message is confusing and a change is needed. |
src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php
Outdated
Show resolved
Hide resolved
I think the attached patch is currently a hack that works around the real issue: the core issue is that Here is a better fix: --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php
@@ -376,7 +376,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
if ($throw) {
throw $e;
}
- $classReflector = false;
+ $classReflector = null;
}
if ($this->trackResources) {
@@ -392,7 +392,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
$this->classReflectors[$class] = $classReflector;
}
- return $classReflector ?: null;
+ return $classReflector;
} Which is correct. It's not as good as the one you're achieving with the class_exists(), but that's another issue: the ErrorHandler should be able to do these suggestions on ReflectionException too, not only on fatal errors. - This last part would be for 4.4. Makes sense? |
See #34282 |
Thanks for raising the point! |
Thank you for improving the PR. |
This PR was merged into the 3.4 branch. Discussion ---------- [DI] Dont cache classes with missing parents | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Closes #34239 | License | MIT | Doc PR | - Commits ------- 1606430 [DI] Dont cache classes with missing parents
Im trying to address this issue: https://stackoverflow.com/questions/49958116/class-appbundle-controller-homecontroller-used-for-service-appbundle-controll
So here is the scenario:
Since
StartpageController
is autowired and tagged withcontroller.service_arguments
we will run it inRegisterControllerArgumentLocatorsPass
.If my cache folder is empty, I will get an error saying something like:
That does not make any sense.
This PR is trying to load
App\Bar\StartpageController
to make PHP discover that we are missing something. Now I will get a much better error:If for some reason this is not the issue and PHP does not throw this error, we just continue with the normal exception.