Implement TWIG_GET_CLASS_NAME and make use of it.
authorDerick Rethans <github@derickrethans.nl>
Thu, 30 Jun 2011 13:25:45 +0000 (14:25 +0100)
committerDerick Rethans <github@derickrethans.nl>
Thu, 30 Jun 2011 13:36:05 +0000 (14:36 +0100)
twig.c

diff --git a/twig.c b/twig.c
index 02dfa2b..96b8e5b 100644 (file)
--- a/twig.c
+++ b/twig.c
@@ -339,6 +339,18 @@ static void TWIG_THROW_EXCEPTION(char *exception_name, char *message, ...)
        zend_throw_exception_ex(*pce, 0 TSRMLS_CC, buffer);
 }
 
+char *TWIG_GET_CLASS_NAME(zval *object)
+{
+       char *class_name;
+       zend_uint class_name_len;
+
+       if (Z_TYPE_P(object) != IS_OBJECT) {
+               return "";
+       }
+       zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
+       return class_name;
+}
+
 static void twig_add_method_to_class(zend_function *mptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
 {
        zval *retval = va_arg(args, zval*);
@@ -479,7 +491,7 @@ PHP_FUNCTION(twig_template_get_attributes)
        }
 */
                        if (Z_TYPE_P(object) == IS_OBJECT) {
-                               TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" in object (with ArrayAccess) of type \"%s\" does not exist", Z_STRVAL_P(item), TWIG_GET_CLASS(object));
+                               TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" in object (with ArrayAccess) of type \"%s\" does not exist", Z_STRVAL_P(item), TWIG_GET_CLASS_NAME(object));
                        } else {
                                TWIG_THROW_EXCEPTION("Twig_Error_Runtime", "Key \"%s\" for array with keys \"%s\" does not exist", Z_STRVAL_P(item), TWIG_IMPLODE_ARRAY_KEYS(", ", object));
                        }
@@ -525,11 +537,9 @@ PHP_FUNCTION(twig_template_get_attributes)
                }
        }
 */
-       char *class_name;
-       zend_uint class_name_len;
+       char *class_name = TWIG_GET_CLASS_NAME(object);
        zval *tmp_self_cache;
        
-       zend_get_object_classname(object, &class_name, &class_name_len TSRMLS_CC);
        tmp_self_cache = TWIG_GET_STATIC_PROPERTY(template, "cache");
 
        if (!TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name)) {