-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] #[When(env: 'staging')]
throws exception when using dev-only classes
#51106
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
Comments
You might want to see if ClassExistenceResource::throwOnRequiredClass is called when this happens, and if it's called, debug what happens in it. |
Hi, As you pointed it out, my exception is handled by Howerver, condition symfony/src/Symfony/Component/Config/Resource/ClassExistenceResource.php Lines 149 to 155 in 42d9d7c
The only other case where it can skip the error is based on symfony/src/Symfony/Component/Config/Resource/ClassExistenceResource.php Lines 193 to 209 in 42d9d7c
But this occurs during an In the end, error is thrown as a |
I guess this is a side effect or missing case of php/php-src#4697 I tried to add a dummy service with inexistant trait on PHP 7.3.33, no errors. If I switch to PHP 7.3.7, as mentioned here #32395, I got an exception
Switching to a version 7.3.6 doesn't throw an exception There is also this issue #32995 for PHP 7.4 but was resolved in php-src |
Hey, thanks for your report! |
Hello? This issue is about to be closed if nobody replies. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Symfony version(s) affected
5.4, 6.3
Description
When I add
#[When(env: 'staging')]
attribute to a service that should only be used instaging
environment, I got an exception about a missing class.That's totally fair, because the trait referenced here (
IsAServiceTrait
) is only installed in dev environment.What I don't understand, is that
ReflectionException
should be caught heresymfony/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
Lines 292 to 297 in 42d9d7c
But I never reach this catch block and
Symfony\Component\ErrorHandler\ErrorHandler::handleFatalError
get called insteadsymfony/src/Symfony/Component/ErrorHandler/ErrorHandler.php
Line 569 in 42d9d7c
How to reproduce
This is the minimal reproducer I can get
Nelmio/Alice doesn't need to be in composer.json (even if in my real project, it is). What matters here is to have a conditional service using a class only available when doing
composer install
and notcomposer install --no-dev
.Another important thing to note: if I comment
use IsAServiceTrait
and I want to inject an inexistant service, everything works finePossible Solution
No response
Additional Context
IsAServiceTrait
comes from https://github.com/nelmio/alice/blob/a020c0767e10dbb7bf1c193e16e94710691133d9/src/IsAServiceTrait.phpThe text was updated successfully, but these errors were encountered: