From 19fbee7ef66b97f34dc4bdd147ceffb96607426e Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Tue, 7 Jun 2011 09:29:02 +0100 Subject: [PATCH] - Implemented TWIG_ARRAY_KEY_EXISTS (for normal arrays only). --- twig.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/twig.c b/twig.c index 0a53c74..27ad3ac 100644 --- a/twig.c +++ b/twig.c @@ -113,6 +113,20 @@ PHP_MINFO_FUNCTION(twig) } +int TWIG_ARRAY_KEY_EXISTS(zval *array, zval *key) +{ + void *dummy; + + if (Z_TYPE_P(array) != IS_ARRAY) { + return 0; + } + convert_to_string(key); + if (zend_hash_find(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &dummy) == SUCCESS) { + return 1; + } + return 0; +} + /* {{{ proto mixed twig_template_get_attributes(TwigTemplate template, mixed object, mixed item, array arguments, string type, boolean isDefinedTest) A C implementation of TwigTemplate::getAttribute() */ PHP_FUNCTION(twig_template_get_attributes) @@ -143,7 +157,7 @@ PHP_FUNCTION(twig_template_get_attributes) } */ if (strcmp("method", type) == 0) { - if ((Z_TYPE_P(object) == IS_ARRAY && TWIG_ARRAY_KEY_EXISTS(item, object)) + if ((TWIG_ARRAY_KEY_EXISTS(object, item)) || (TWIG_INSTANCE_OF(object, "ArrayAccess") && TWIG_ISSET_ARRAY_ELEMENT(object, item)) ) { if (isDefinedTest) { @@ -242,7 +256,7 @@ PHP_FUNCTION(twig_template_get_attributes) */ if (strcmp("method", type) != 0) { if (TWIG_ISSET("self::$cache[$class]['properties'][$item]") - || TWIG_ISSET(object, item) || TWIG_ARRAY_KEY_EXISTS(item, object) + || TWIG_ISSET(object, item) || TWIG_ARRAY_KEY_EXISTS(object, item) // FIXME: Array key? is that array access here? ) { if (isDefinedTest) { RETURN_TRUE; -- 1.7.2.5