-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Update all
method to handle default value
#38891
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
6fc5b95
to
736f575
Compare
Indeed, the other way to fix my DX issue here would be to add a second parameter to |
I'd prefer to avoid adding a new method. |
736f575
to
834a99b
Compare
@fabpot I updated |
834a99b
to
86b8c45
Compare
all
method to handle default value
Honestly, I don't see why we should add an API for this when there is already a language construct for it...
better learn the language than a specific API, this makes it easier for everyone, readers and writters. |
86b8c45
to
e1fa458
Compare
@nicolas-grekas It's more about consistency than learn a language, all getters in ParameterBag has a default parameter to handle this behavior that's why I think it's better to keep it the same way there. |
mmm, I'm not convinced. All the other methods return single items. BTW, the |
I tend to agree with @nicolas-grekas arguments. Let's close. Thanks for the discussion. |
I added a quickgetArray
method for better DX after #34363 changes.I know we can use
all($key)
(and #37229 did almost same addition) with the same purpose but here this method will be here for its default value mostly which is not handled byall($key)
method.I think it's better DX to do
getArray($key, $default)
rather thanall($key) ?? $default
I updated
all()
method to handle a$default
variable as second parameter as following:all(string $key = null, array $default = [])
.