Skip to content

Commit 4773c5e

Browse files
committed
bug #37327 [HttpFoundation] Allow null in InputBag@set (taylorotwell)
This PR was squashed before being merged into the 5.1 branch (closes #37327). Discussion ---------- [HttpFoundation] Allow `null` in InputBag@set This allows `null` to be passed to InputBag's `set` method. | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT Previously, `null` was an allowed value to the InputBag's `set` method. At some point this was deprecated. It would be very nice for us to be able to set this to `null`. For example, this ability drives a very popular feature of Laravel where we ship a middleware that converts all empty strings to `null` on incoming requests. Note that the `get` method already specifically allows `null` and `null` is a valid decoded JSON value. Commits ------- 14ec6a7 [HttpFoundation] Allow `null` in InputBag@set
2 parents bf2fb93 + 14ec6a7 commit 4773c5e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Symfony/Component/HttpFoundation/InputBag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ public function add(array $inputs = [])
7272
/**
7373
* Sets an input by name.
7474
*
75-
* @param string|array $value
75+
* @param string|array|null $value
7676
*/
7777
public function set(string $key, $value)
7878
{
79-
if (!is_scalar($value) && !\is_array($value) && !method_exists($value, '__toString')) {
80-
trigger_deprecation('symfony/http-foundation', '5.1', 'Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string or an array instead.', get_debug_type($value), __METHOD__);
79+
if (null !== $value && !is_scalar($value) && !\is_array($value) && !method_exists($value, '__toString')) {
80+
trigger_deprecation('symfony/http-foundation', '5.1', 'Passing "%s" as a 2nd Argument to "%s()" is deprecated, pass a string, array, or null instead.', get_debug_type($value), __METHOD__);
8181
}
8282

8383
$this->parameters[$key] = $value;

src/Symfony/Component/HttpFoundation/Tests/InputBagTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testFilterArray()
5151
public function testSetWithNonStringishOrArrayIsDeprecated()
5252
{
5353
$bag = new InputBag();
54-
$this->expectDeprecation('Since symfony/http-foundation 5.1: Passing "Symfony\Component\HttpFoundation\InputBag" as a 2nd Argument to "Symfony\Component\HttpFoundation\InputBag::set()" is deprecated, pass a string or an array instead.');
54+
$this->expectDeprecation('Since symfony/http-foundation 5.1: Passing "Symfony\Component\HttpFoundation\InputBag" as a 2nd Argument to "Symfony\Component\HttpFoundation\InputBag::set()" is deprecated, pass a string, array, or null instead.');
5555
$bag->set('foo', new InputBag());
5656
}
5757

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy