From 759a77d0408a67791d6da8e241d2dc24d8b78056 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Tue, 5 Aug 2014 17:25:10 +0100 Subject: [PATCH] [Ext] updating Twig extension for previous commit --- ext/twig/twig.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ext/twig/twig.c b/ext/twig/twig.c index 5cb923f..5c482be 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -830,7 +830,11 @@ PHP_FUNCTION(twig_template_get_attributes) } elseif (is_object($object)) { $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface', $item, get_class($object)); } elseif (is_array($object)) { - $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + if (empty($object)) { + $message = sprintf('Key "%s" does not exist as the array is empty', $arrayItem); + } else { + $message = sprintf('Key "%s" for array with keys "%s" does not exist', $arrayItem, implode(', ', array_keys($object))); + } } elseif (Twig_Template::ARRAY_CALL === $type) { $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s")', $item, gettype($object), $object); } else { @@ -845,7 +849,11 @@ PHP_FUNCTION(twig_template_get_attributes) } else if (Z_TYPE_P(object) == IS_OBJECT) { TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Impossible to access a key \"%s\" on an object of class \"%s\" that does not implement ArrayAccess interface", item, TWIG_GET_CLASS_NAME(object TSRMLS_CC)); } else if (Z_TYPE_P(object) == IS_ARRAY) { - TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist", item, TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC)); + if (0 == zend_hash_num_elements(Z_ARRVAL_P(object))) { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" does not exist as the array is empty", item); + } else { + TWIG_RUNTIME_ERROR(template TSRMLS_CC, "Key \"%s\" for array with keys \"%s\" does not exist", item, TWIG_IMPLODE_ARRAY_KEYS(", ", object TSRMLS_CC)); + } } else { char *type_name = zend_zval_type_name(object); Z_ADDREF_P(object); -- 1.7.2.5