Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
derrabus commentedDec 30, 2021
Either way, allowing enums in parameters would be a new feature. I don't think we should add that functionality to 4.4. |
ogizanagi commentedDec 31, 2021
I kind of agree, despite#40857 being on 4.4. But the difference is parameters never supported objects. |
derrabus commentedDec 31, 2021
Sounds good. 🙂 |
nicolas-grekas commentedJan 12, 2022
How do we move forward on this one? |
ogizanagi commentedJan 12, 2022
Sorry, didn't have time to go further. The plan was to throw either in the |
2a73c69 tod2bea6aCompareogizanagi commentedJan 26, 2022
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.yamlparameters:default_status:!php/const App\Status::Draftstatuses: -!php/constApp\Status::Draft -!php/constApp\Status::Deleted -!php/constApp\Status::Published we might want to handle this specific case here so the user notices it. |
nicolas-grekas commentedJan 28, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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::Caseservices: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. |
ogizanagi commentedJan 28, 2022
Honestly, I'd be way more satisfied this way too :) |
d2bea6a toa3d95d6Compare5a18657 to4eaf136Compareogizanagi commentedJan 31, 2022
Alright, PR updated. Hopefully I haven't missed anything. |
src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
f0acb77 toda3f323CompareUh oh!
There was an error while loading.Please reload this page.
da3f323 toe6fb077Comparefabpot commentedFeb 4, 2022
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. |
nicolas-grekas commentedFeb 4, 2022
This is edgy, but after a private chat with@fabpot, I've got a go for merging. Now doing it. |
nicolas-grekas commentedFeb 4, 2022
Thank you@ogizanagi. |
e6fb077 toac36617Compare
Uh oh!
There was an error while loading.Please reload this page.
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
PhpDumpermisses the leading slash:protected function getDefaultParameters(): array { return [- 'default_status' => App\Status::Draft,+ 'default_status' => \App\Status::Draft, ]; }While this would fix using enums as DI parameters as of Symfony < 6,
the
ParameterBagInterface::get/setandContainerInterface::setParameter/getParameterare not allowing\UnitEnumand 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)