The attached patch alters the var family of functions to be aware of the get_class_name handler for overloaded objects.
It also checks that the object has a hash table for it's properties before attempting to access it. This patch is not 100% complete because it does not handle nested class names. I did not see a zend api function to do this, and IMO there should be such a thing among the introspection functions in PHP 5. Should I commit this patch? --Wez.
Index: ext/standard/var.c =================================================================== RCS file: /repository/php4/ext/standard/var.c,v retrieving revision 1.155 diff -u -p -r1.155 var.c --- ext/standard/var.c 18 Jan 2003 15:03:01 -0000 1.155 +++ ext/standard/var.c 30 Jan 2003 10:50:56 -0000 @@ -60,6 +60,8 @@ static int php_array_element_dump(zval * void php_var_dump(zval **struc, int level TSRMLS_DC) { HashTable *myht = NULL; + char *class_name; + zend_uint class_name_len; if (level > 1) { php_printf("%*c", level - 1, ' '); @@ -93,13 +95,18 @@ void php_var_dump(zval **struc, int leve goto head_done; case IS_OBJECT: myht = Z_OBJPROP_PP(struc); - if (myht->nApplyCount > 1) { + if (myht && myht->nApplyCount > 1) { PUTS("*RECURSION*\n"); return; } - php_printf("%sobject(%s)(%d) {\n", COMMON, Z_OBJCE_PP(struc)->name, zend_hash_num_elements(myht)); + + Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, +&class_name_len, 0 TSRMLS_CC); + + php_printf("%sobject(%s)(%d) {\n", COMMON, class_name, myht ? +zend_hash_num_elements(myht) : 0); head_done: - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level); + if (myht) { + zend_hash_apply_with_arguments(myht, (apply_func_args_t) +php_array_element_dump, 1, level); + } if (level > 1) { php_printf("%*c", level-1, ' '); } @@ -166,6 +173,8 @@ static int zval_array_element_dump(zval void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) { HashTable *myht = NULL; + char *class_name; + zend_uint class_name_len; if (level > 1) { php_printf("%*c", level - 1, ' '); @@ -195,9 +204,12 @@ void php_debug_zval_dump(zval **struc, i goto head_done; case IS_OBJECT: myht = Z_OBJPROP_PP(struc); - php_printf("%sobject(%s)(%d) refcount(%u){\n", COMMON, Z_OBJCE_PP(struc)->name, zend_hash_num_elements(myht), Z_REFCOUNT_PP(struc)); + Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, +&class_name_len, 0 TSRMLS_CC); + php_printf("%sobject(%s)(%d) refcount(%u){\n", COMMON, class_name, +myht ? zend_hash_num_elements(myht) : 0, Z_REFCOUNT_PP(struc)); head_done: - zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level); + if (myht) { + zend_hash_apply_with_arguments(myht, (apply_func_args_t) +zval_array_element_dump, 1, level); + } if (level > 1) { php_printf("%*c", level-1, ' '); } @@ -281,6 +293,8 @@ void php_var_export(zval **struc, int le HashTable *myht; char* tmp_str; int tmp_len; + char *class_name; + zend_uint class_name_len; switch (Z_TYPE_PP(struc)) { case IS_BOOL: @@ -319,8 +333,11 @@ void php_var_export(zval **struc, int le if (level > 1) { php_printf("\n%*c", level - 1, ' '); } - php_printf ("class %s {\n", Z_OBJCE_PP(struc)->name); - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_object_element_export, 1, level); + Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, +&class_name_len, 0 TSRMLS_CC); + php_printf ("class %s {\n", class_name); + if (myht) { + zend_hash_apply_with_arguments(myht, (apply_func_args_t) +php_object_element_export, 1, level); + } if (level > 1) { php_printf("%*c", level - 1, ' '); }
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php