-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Add nullable getters for InputBag
/ParameterBag
#53668
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
Fabbot.io error is unrelated https://fabbot.io/report/symfony/symfony/53668/f6d3c61717fd06c8a5380bc2afbde0fa7efae2ce But I can fix it if wanted. |
We shouldn't have made a difference between "null" and "unset". Is there a path toward this instead? |
f6d3c61
to
41cde15
Compare
It would require to change
to
This would a BC-break, I don't know the impact. The usage of I don't know why this behavior was preferred, but there are some tests about it @nicolas-grekas, like
I made the change. |
/** | ||
* Returns the parameter value converted to boolean or null. | ||
*/ | ||
public function getBooleanOrNull(string $key, ?bool $default = null): ?bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use Boolean (long) but Int (short), what about using either getIntegerOrNull
or getBoolOrNull
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree this is weird, but the decision should be taken first on getBoolean
and getInt
.
I'll be happy to update my PR as soon as a decision is taken first on which method between getBoolean
and getInt
should be deprecated (in favor of getBool
or getInteger
)
InputBag
/ParameterBag
Yes, but @nicolas-grekas said
If Symfony doesn't want to make a difference between null and unset, the method isset should be preferred over array_key_exist. |
Not sure about the status of this PR @nicolas-grekas @OskarStark, is there something I need to change ? I answered #53668 (comment) and #53668 (comment) and was waiting about your feedback again :) |
Rework of the #49972 PR.
The
getNullable*
are different from thebecause the
has
check is usingarray_key_exists
.So in case of a custom bag build with
null
values, the getNullable method will return null, when the has/get* will cast the value (or throw an error in some cases).The
getNullable*
is also different from the\FILTER_NULL_ON_FAILURE
flag because becausegetNullable*
methods are still validating non-null values and throwing exception (when the FILTER_NULL_ON_FAILURE flag fallback to null).So currently, the
getNullable*
behavior is not an easy one to produce with the given methods from Symfony.The #45775 issue was closed without the nullable getters, but this was still a requested feature.