From 97f463c156317588b952193fe5cbe18876c90383 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 10 Mar 2006 08:42:56 +0000 Subject: [PATCH] Fixed debug_zval_dump() to support private and protected members --- NEWS | 1 + ext/standard/var.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f4f61aaa918..9da6e6cdb1b 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? Mar 2006, PHP 5.1.3RC2 +- Fixed debug_zval_dump() to support private and protected members. (Dmitry) 09 Mar 2006, PHP 5.1.3RC1 - Updated PCRE to version 6.6. (Andrei) diff --git a/ext/standard/var.c b/ext/standard/var.c index e02d5ce3fc3..7d107f171ac 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -221,12 +221,44 @@ static int zval_array_element_dump(zval **zv, int num_args, va_list args, zend_h return 0; } +static int zval_object_property_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) +{ + int level; + char *prop_name, *class_name; + TSRMLS_FETCH(); + + level = va_arg(args, int); + + if (hash_key->nKeyLength ==0 ) { /* numeric key */ + php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h); + } else { /* string key */ + zend_unmangle_property_name_ex(hash_key->arKey, hash_key->nKeyLength, &class_name, &prop_name); + if (class_name) { + php_printf("%*c[\"%s", level + 1, ' ', prop_name); + if (class_name[0]=='*') { + ZEND_PUTS(":protected"); + } else { + ZEND_PUTS(":private"); + } + } else { + php_printf("%*c[\"%s", level + 1, ' ', hash_key->arKey); +#ifdef ANDREY_0 + ZEND_PUTS(":public"); +#endif + } + ZEND_PUTS("\"]=>\n"); + } + php_debug_zval_dump(zv, level + 2 TSRMLS_CC); + return 0; +} + PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) { HashTable *myht = NULL; char *class_name; zend_uint class_name_len; zend_class_entry *ce; + int (*zval_element_dump_func)(zval**, int, va_list, zend_hash_key*); if (level > 1) { php_printf("%*c", level - 1, ' '); @@ -257,6 +289,7 @@ PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) return; } php_printf("%sarray(%d) refcount(%u){\n", COMMON, zend_hash_num_elements(myht), Z_REFCOUNT_PP(struc)); + zval_element_dump_func = zval_array_element_dump; goto head_done; case IS_OBJECT: myht = Z_OBJPROP_PP(struc); @@ -268,9 +301,10 @@ PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC); php_printf("%sobject(%s)#%d (%d) refcount(%u){\n", COMMON, class_name, Z_OBJ_HANDLE_PP(struc), myht ? zend_hash_num_elements(myht) : 0, Z_REFCOUNT_PP(struc)); efree(class_name); + zval_element_dump_func = zval_object_property_dump; head_done: if (myht) { - zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1)); + zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_element_dump_func, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1)); } if (level > 1) { php_printf("%*c", level-1, ' ');