Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5a802a

Browse files
committed
[DependencyInjection] Add nice exception when using non-scalar parameter as array key
1 parent fa7703b commit f5a802a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,13 @@ public function resolveValue(mixed $value, array $resolving = []): mixed
163163
{
164164
if (\is_array($value)) {
165165
$args = [];
166-
foreach ($value as $k => $v) {
167-
$args[\is_string($k) ? $this->resolveValue($k, $resolving) : $k] = $this->resolveValue($v, $resolving);
166+
foreach ($value as $key => $v) {
167+
$resolvedKey = \is_string($key) ? $this->resolveValue($key, $resolving) : $key;
168+
if (!\is_scalar($resolvedKey) && !$resolvedKey instanceof \Stringable) {
169+
throw new RuntimeException(sprintf('Array keys must be a scalar-value, but found key "%s" to resolve to type "%s".', $key, get_debug_type($resolvedKey)));
170+
}
171+
172+
$args[$resolvedKey] = $this->resolveValue($v, $resolving);
168173
}
169174

170175
return $args;

0 commit comments

Comments
 (0)