-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection][FrameworkBundle] Fix using PHP 8.1 enum as parameters #44868
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
Either way, allowing enums in parameters would be a new feature. I don't think we should add that functionality to 4.4. |
I kind of agree, despite #40857 being on 4.4. But the difference is parameters never supported objects. |
Sounds good. 🙂 |
How do we move forward on this one? |
Sorry, didn't have time to go further. The plan was to throw either in the |
2a73c69
to
d2bea6a
Compare
Updated the PR so that we simply throw on attempting to set an enum or array containing an enum as a DI parameter : this should be enough for our goal: explicit the fact enums aren't supported as such. # services.yaml
parameters:
default_status: !php/const App\Status::Draft
statuses:
- !php/const App\Status::Draft
- !php/const App\Status::Deleted
- !php/const App\Status::Published we might want to handle this specific case here so the user notices it. |
I'm sorry I'm not super convinced by this. It would be strange to me to allow direct references to enums in service arguments, but to disallow indirect references via DI parameters: parameters:
foo: !php/const Some\Enum::Case
services:
bar: ['%foo%'] I'd prefer to fix supporting them when dumping, and widen the types on 6.0. I don't think anybody is going to be hit by the BC break. |
Honestly, I'd be way more satisfied this way too :) |
d2bea6a
to
a3d95d6
Compare
5a18657
to
4eaf136
Compare
Alright, PR updated. Hopefully I haven't missed anything. |
src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php
Outdated
Show resolved
Hide resolved
f0acb77
to
da3f323
Compare
da3f323
to
e6fb077
Compare
We stopped adding new features for supporting newer PHP versions a while ago, so this is a new feature that should go into 6.1. |
This is edgy, but after a private chat with @fabpot, I've got a go for merging. Now doing it. |
Thank you @ogizanagi. |
e6fb077
to
ac36617
Compare
While #40857 allowed using enums in DI, it does not allow using these in parameters.
This would be the actual fix for #44834, which shows the error you'll get trying to use enum as DI parameters (appart from the binding issue fixed in #44838):
given:
The exception happens because the
PhpDumper
misses the leading slash:While this would fix using enums as DI parameters as of Symfony < 6,
the
ParameterBagInterface::get/set
andContainerInterface::setParameter/getParameter
are not allowing\UnitEnum
and adding these in phpdoc is an issue since actual typehints and return types were added as of Symfony 6.=> So this PR is a BC break, but hopefully nobody will be hit by it 🤞🏻
(poke @ismail1432 -
https://twitter.com/SmaineDev/status/1476237072826613763?s=20)