Implemented TWIG_RETURN_ARRAY_ELEMENT.
authorDerick Rethans <github@derickrethans.nl>
Thu, 30 Jun 2011 10:25:57 +0000 (11:25 +0100)
committerDerick Rethans <github@derickrethans.nl>
Thu, 30 Jun 2011 10:25:57 +0000 (11:25 +0100)
twig.c

diff --git a/twig.c b/twig.c
index a072ca3..f365ab7 100644 (file)
--- a/twig.c
+++ b/twig.c
@@ -154,9 +154,18 @@ int TWIG_ISSET_ARRAY_ELEMENT(zval *array, zval *item)
        return 0;
 }
 
-zval *TWIG_RETURN_ARRAY_ELEMENT(zval *object, zval *item)
+zval *TWIG_RETURN_ARRAY_ELEMENT(zval *array, zval *key)
 {
+       void *dummy;
 
+       if (Z_TYPE_P(array) != IS_ARRAY) {
+               return NULL;
+       }
+       convert_to_string(key);
+       if (zend_hash_find(Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &dummy) == SUCCESS) {
+               return dummy;
+       }
+       return NULL;
 }
 
 zval *TWIG_PROPERTY(zval *object, char *propname)