-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fix deprecation in InputBag
for non-scalar values
#46936
New issue
8000Have 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
InputBag
for non-scalar values
@@ -35,8 +35,8 @@ public function get(string $key, $default = null) | |||
|
|||
$value = parent::get($key, $this); | |||
|
|||
if (null !== $value && $this !== $value && !\is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { |
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.
the __toString()
existence check is still relevant as it means the value can be cast to string despite is_scalar()
doesn't recognize it as such
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.
True - but that check is missing in 6.x. So either the check in 5.4 needs to match the one in 6.x - or vice versa.
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.
I'd say it's a bug on 6.x then, given there's a instanceof \Stringable
check (equivalent to the __toString()
existence check as 6.x requires PHP 8) for $default
above as well as in InputBag::set()
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.
Good point. Then this PR should only change the wording while the instanceof \Stringable
check needs to be added in InputBag::get
in 6.x.
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.
Correct 👍
Good catch, thanks @fritzmg. |
…et()` (chalasr) This PR was merged into the 6.0 branch. Discussion ---------- [HttpFoundation] Fix `\Stringable` support in `InputBag::get()` | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Spotted in #46936 (comment), thanks @fritzmg. Commits ------- 6dfe92e [HttpFoundation] Fix `\Stringable` support in `InputBag::get()`
…et()` (chalasr) This PR was merged into the 6.0 branch. Discussion ---------- [HttpFoundation] Fix `\Stringable` support in `InputBag::get()` | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Spotted in symfony/symfony#46936 (comment), thanks @fritzmg. Commits ------- 6dfe92e091 [HttpFoundation] Fix `\Stringable` support in `InputBag::get()`
In Symfony 6.0,
InputBag::get
was changed so that when you are retrieving a non-scalar value from it, it will throw aBadRequestException
. This is also correctly documented in the UPGRADE.md. However, the deprecation in Symfony 5.4 assumes something different: it says that non-string values are deprecated. This PR fixes that.