mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
fixed getAttribute for array access with a boolean or float key
This commit is contained in:
@@ -338,14 +338,16 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
|||||||
{
|
{
|
||||||
// array
|
// array
|
||||||
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
||||||
if ((is_array($object) && array_key_exists((string) $item, $object))
|
$arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item;
|
||||||
|| ($object instanceof ArrayAccess && isset($object[(string) $item]))
|
|
||||||
|
if ((is_array($object) && array_key_exists($arrayItem, $object))
|
||||||
|
|| ($object instanceof ArrayAccess && isset($object[$arrayItem]))
|
||||||
) {
|
) {
|
||||||
if ($isDefinedTest) {
|
if ($isDefinedTest) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $object[(string) $item];
|
return $object[$arrayItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Twig_TemplateInterface::ARRAY_CALL === $type) {
|
if (Twig_TemplateInterface::ARRAY_CALL === $type) {
|
||||||
@@ -358,11 +360,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($object)) {
|
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)) {
|
} 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 {
|
} 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user