mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 04:46:49 +00:00
fix numeric keys in array
This commit is contained in:
@@ -336,18 +336,16 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
|||||||
*/
|
*/
|
||||||
protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
|
protected function getAttribute($object, $item, array $arguments = array(), $type = Twig_TemplateInterface::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false)
|
||||||
{
|
{
|
||||||
$item = ctype_digit((string) $item) ? (int) $item : (string) $item;
|
|
||||||
|
|
||||||
// array
|
// array
|
||||||
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
||||||
if ((is_array($object) && array_key_exists($item, $object))
|
if ((is_array($object) && array_key_exists((string) $item, $object))
|
||||||
|| ($object instanceof ArrayAccess && isset($object[$item]))
|
|| ($object instanceof ArrayAccess && isset($object[(string) $item]))
|
||||||
) {
|
) {
|
||||||
if ($isDefinedTest) {
|
if ($isDefinedTest) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $object[$item];
|
return $object[(string) $item];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Twig_TemplateInterface::ARRAY_CALL === $type) {
|
if (Twig_TemplateInterface::ARRAY_CALL === $type) {
|
||||||
@@ -385,7 +383,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
|||||||
|
|
||||||
// object property
|
// object property
|
||||||
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
|
||||||
if (isset($object->$item) || array_key_exists($item, $object)) {
|
if (isset($object->$item) || array_key_exists((string) $item, $object)) {
|
||||||
if ($isDefinedTest) {
|
if ($isDefinedTest) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -405,13 +403,13 @@ abstract class Twig_Template implements Twig_TemplateInterface
|
|||||||
|
|
||||||
$lcItem = strtolower($item);
|
$lcItem = strtolower($item);
|
||||||
if (isset(self::$cache[$class]['methods'][$lcItem])) {
|
if (isset(self::$cache[$class]['methods'][$lcItem])) {
|
||||||
$method = $item;
|
$method = (string) $item;
|
||||||
} elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
|
} elseif (isset(self::$cache[$class]['methods']['get'.$lcItem])) {
|
||||||
$method = 'get'.$item;
|
$method = 'get'.$item;
|
||||||
} elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) {
|
} elseif (isset(self::$cache[$class]['methods']['is'.$lcItem])) {
|
||||||
$method = 'is'.$item;
|
$method = 'is'.$item;
|
||||||
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
|
} elseif (isset(self::$cache[$class]['methods']['__call'])) {
|
||||||
$method = $item;
|
$method = (string) $item;
|
||||||
} else {
|
} else {
|
||||||
if ($isDefinedTest) {
|
if ($isDefinedTest) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user