Skip to content

Commit a194922

Browse files
committed
Don't call method_exists() with non-objects.
1 parent ba5a2d7 commit a194922

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

InputBag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ final class InputBag extends ParameterBag
2929
*/
3030
public function get(string $key, $default = null)
3131
{
32-
if (null !== $default && !is_scalar($default) && !method_exists($default, '__toString')) {
32+
if (null !== $default && !is_scalar($default) && !(\is_object($default) && method_exists($default, '__toString'))) {
3333
trigger_deprecation('symfony/http-foundation', '5.1', 'Passing a non-string value as 2nd argument to "%s()" is deprecated, pass a string or null instead.', __METHOD__);
3434
}
3535

3636
$value = parent::get($key, $this);
3737

38-
if (null !== $value && $this !== $value && !is_scalar($value) && !method_exists($value, '__toString')) {
38+
if (null !== $value && $this !== $value && !is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
3939
trigger_deprecation('symfony/http-foundation', '5.1', 'Retrieving a non-string value from "%s()" is deprecated, and will throw a "%s" exception in Symfony 6.0, use "%s::all()" instead.', __METHOD__, BadRequestException::class, __CLASS__);
4040
}
4141

@@ -87,7 +87,7 @@ public function add(array $inputs = [])
8787
*/
8888
public function set(string $key, $value)
8989
{
90-
if (!is_scalar($value) && !method_exists($value, '__toString') && !\is_array($value)) {
90+
if (!is_scalar($value) && !\is_array($value) && !method_exists($value, '__toString')) {
9191
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__);
9292
}
9393

0 commit comments

Comments
 (0)