8000 Fix deprecation in `InputBag` for non-scalar values by fritzmg · Pull Request #46936 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix deprecation in InputBag for non-scalar values #46936

New issue 8000

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

Merged
merged 3 commits into from
Jul 15, 2022
Merged

Conversation

fritzmg
Copy link
Contributor
@fritzmg fritzmg commented Jul 14, 2022
Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

In Symfony 6.0, InputBag::get was changed so that when you are retrieving a non-scalar value from it, it will throw a BadRequestException. 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.

@OskarStark OskarStark changed the title Fix deprecation in InputBag for non-scalar values Fix deprecation in InputBag for non-scalar values Jul 14, 2022
@@ -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'))) {
Copy link
Member
@chalasr chalasr Jul 14, 2022

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

Copy link
Contributor Author

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.

Copy link
Member

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()

Copy link
Contributor Author
@fritzmg fritzmg Jul 14, 2022

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct 👍

@chalasr
Copy link
Member
chalasr commented Jul 15, 2022

Good catch, thanks @fritzmg.

@chalasr chalasr merged commit f9e8317 into symfony:5.4 Jul 15, 2022
@fritzmg fritzmg deleted the patch-3 branch July 16, 2022 12:30
fabpot added a commit that referenced this pull request Jul 22, 2022
…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()`
symfony-splitter pushed a commit to symfony/http-foundation that referenced this pull request Jul 22, 2022
…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()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0