You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #4704 Fix accessing arrays with stringable objects as key (nicolas-grekas)
This PR was merged into the 3.x branch.
Discussion
----------
Fix accessing arrays with stringable objects as key
Fix#4701
Commits
-------
9ae75d3 Fix accessing arrays with stringable objects as key
@@ -1715,9 +1715,13 @@ public static function getAttribute(Environment $env, Source $source, $object, $
1715
1715
}
1716
1716
1717
1717
if ($objectinstanceof \ArrayAccess) {
1718
-
$message = \sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, $object::class);
1718
+
if (\is_object($arrayItem) || \is_array($arrayItem)) {
1719
+
$message = \sprintf('Key of type "%s" does not exist in ArrayAccess-able object of class "%s".', get_debug_type($arrayItem), get_debug_type($object));
1720
+
} else {
1721
+
$message = \sprintf('Key "%s" does not exist in ArrayAccess-able object of class "%s".', $arrayItem, get_debug_type($object));
1722
+
}
1719
1723
} elseif (\is_object($object)) {
1720
-
$message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, $object::class);
1724
+
$message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, get_debug_type($object));
1721
1725
} elseif (\is_array($object)) {
1722
1726
if (!$object) {
1723
1727
$message = \sprintf('Key "%s" does not exist as the sequence/mapping is empty.', $arrayItem);
0 commit comments