FOSRestBundle
FOSRestBundle copied to clipboard
When setting a default parameter to null, '' is set instead
With the query param as follow:
@QueryParam(
name="param1",
strict=false,
nullable=true,
default=null,
allowBlank=false,
requirements="11|12|13|14"
)
When I format the url as such: /rest/v0/myroute?param1=, I expect to get param1 to null in my controller. But I got an empty string instead
It's because of the code at line 268 of ParamFetcher.php
return null === $default ? '' : $default;
Is there any way to avoid that? I just would like to understand why this behavior was chosen instead of simply returning a null value. If not possible, I'll just set the strict mode.
Thank you!
I guess that's because we don't know if your default value was manually set or not (null
is the default value of php).
Is there a reason it should not be as simple as :
return $default;
in that case? If not, I don't understand why.
This issue is causing me some trouble too.
I'd like to second the suggestion that this can just return $default;
Otherwise there's currently no way you can configure ParamFetcher to return null (which is what I want in my use case), but if you just return $default, then you can configure it to return '' if you want by directly specifying that as the default, so it allows the most flexibility.
I agree. WDYT @lsmith77 @xabbuh ?
Sounds reasonable to.
@Ener-Getick As you did that in #1097, do you remember why you did it this way?
@xabbuh in fact it was introduced by @Seldaek here.
@xabbuh Apparently the reason was bc (see this comment) so we can safely change it.
Yeah, let's do that and document it in the upgrade document.
Can confirm the issue since upgrading to v2.0.
What is the state of the issue?
+1 .. that being said, since we did the stable release it is technically a BC break but we can call it a bug fix, since we didn't intend to carry over BC hacks from 1.x
Any news?
This is still an issue, any news?
+1 it seems to me that we should be able to have null as a default value. Make a lot more sense to me than ''