From da616c516995bb5dbb99670b3115e1ec7fd08fdb Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 31 Oct 2012 17:04:56 +0100 Subject: [PATCH] fixed getAttribute for array access with a boolean or float key --- lib/Twig/Template.php | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index c73ad4d..95e0819 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -338,14 +338,16 @@ abstract class Twig_Template implements Twig_TemplateInterface { // array if (Twig_TemplateInterface::METHOD_CALL !== $type) { - if ((is_array($object) && array_key_exists((string) $item, $object)) - || ($object instanceof ArrayAccess && isset($object[(string) $item])) + $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; + + if ((is_array($object) && array_key_exists($arrayItem, $object)) + || ($object instanceof ArrayAccess && isset($object[$arrayItem])) ) { if ($isDefinedTest) { return true; } - return $object[(string) $item]; + return $object[$arrayItem]; } if (Twig_TemplateInterface::ARRAY_CALL === $type) { @@ -358,11 +360,11 @@ abstract class Twig_Template implements Twig_TemplateInterface } if (is_object($object)) { - throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName()); + throw new Twig_Error_Runtime(sprintf('Key "%s" in object (with ArrayAccess) of type "%s" does not exist', $arrayItem, get_class($object)), -1, $this->getTemplateName()); } elseif (is_array($object)) { - throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $item, implode(', ', array_keys($object))), -1, $this->getTemplateName()); + throw new Twig_Error_Runtime(sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))), -1, $this->getTemplateName()); } else { - throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $item, gettype($object)), -1, $this->getTemplateName()); + throw new Twig_Error_Runtime(sprintf('Impossible to access a key ("%s") on a "%s" variable', $arrayItem, gettype($object)), -1, $this->getTemplateName()); } } } -- 1.7.2.5