diff --git a/src/Template.php b/src/Template.php index 435f8c67e1..3f7447c126 100644 --- a/src/Template.php +++ b/src/Template.php @@ -537,7 +537,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s if (self::METHOD_CALL !== $type) { $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; - if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object))) + if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object))) || ($object instanceof \ArrayAccess && isset($object[$arrayItem])) ) { if ($isDefinedTest) { @@ -604,7 +604,7 @@ protected function getAttribute($object, $item, array $arguments = [], $type = s // object property if (self::METHOD_CALL !== $type && !$object instanceof self) { // \Twig\Template does not have public properties, and we don't want to allow access to internal ones - if (isset($object->$item) || \array_key_exists((string) $item, $object)) { + if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) { if ($isDefinedTest) { return true; }