RE: [PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_var.h var.c

From: Date: Sun, 10 Feb 2002 14:19:27 +0000
Subject: RE: [PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_var.h var.c
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9337@lists.php.net to get a copy of this message
Great, but... IMHO it would be better to return the result instead of echoing it, this would make the function more flexible. Say for example that you would like to log the output from it, the way it´s implemented now you´d have to use output buffering to capture the output for logging. regards, Marten. > -----Original Message----- > From: Jason Greene [mailto:jason@inetgurus.net] > Sent: Sunday, February 10, 2002 7:53 AM > To: php-cvs@lists.php.net > Subject: [PHP-CVS] cvs: php4 /ext/standard basic_functions.c php_var.h > var.c > > > jason Sun Feb 10 01:52:35 2002 EDT > > Modified files: > /php4/ext/standard basic_functions.c php_var.h var.c > Log: > @Added zval_debug_dump which works similar to var_dump yet > displays extra > internal information such as refcounts, and the true type names (Jason) > > > Index: php4/ext/standard/basic_functions.c > diff -u php4/ext/standard/basic_functions.c:1.440 > php4/ext/standard/basic_functions.c:1.441 > --- php4/ext/standard/basic_functions.c:1.440 Fri Jan 25 10:43:58 2002 > +++ php4/ext/standard/basic_functions.c Sun Feb 10 01:52:35 2002 > @@ -17,7 +17,7 @@ > > +----------------------------------------------------------------------+ > */ > > -/* $Id: basic_functions.c,v 1.440 2002/01/25 15:43:58 derick Exp $ */ > +/* $Id: basic_functions.c,v 1.441 2002/02/10 06:52:35 jason Exp $ */ > > #include "php.h" > #include "php_main.h" > @@ -516,6 +516,7 @@ > > PHP_FE(var_dump, > NULL) > PHP_FE(var_export, > NULL) > + PHP_FE(zval_debug_dump, > NULL) > PHP_FE(print_r, > NULL) > > PHP_FE(register_shutdown_function, > NULL) > Index: php4/ext/standard/php_var.h > diff -u php4/ext/standard/php_var.h:1.17 php4/ext/standard/php_var.h:1.18 > --- php4/ext/standard/php_var.h:1.17 Tue Dec 11 10:30:35 2001 > +++ php4/ext/standard/php_var.h Sun Feb 10 01:52:35 2002 > @@ -16,7 +16,7 @@ > > +----------------------------------------------------------------------+ > */ > > -/* $Id: php_var.h,v 1.17 2001/12/11 15:30:35 sebastian Exp $ */ > +/* $Id: php_var.h,v 1.18 2002/02/10 06:52:35 jason Exp $ */ > > #ifndef PHP_VAR_H > #define PHP_VAR_H > @@ -25,11 +25,13 @@ > > PHP_FUNCTION(var_dump); > PHP_FUNCTION(var_export); > +PHP_FUNCTION(zval_debug_dump); > PHP_FUNCTION(serialize); > PHP_FUNCTION(unserialize); > > void php_var_dump(zval **struc, int level TSRMLS_DC); > void php_var_export(zval **struc, int level TSRMLS_DC); > +void php_zval_debug_dump(zval **struc, int level TSRMLS_DC); > > /* typdef HashTable php_serialize_data_t; */ > #define php_serialize_data_t HashTable > Index: php4/ext/standard/var.c > diff -u php4/ext/standard/var.c:1.125 php4/ext/standard/var.c:1.126 > --- php4/ext/standard/var.c:1.125 Sat Dec 15 09:55:18 2001 > +++ php4/ext/standard/var.c Sun Feb 10 01:52:35 2002 > @@ -36,6 +36,7 @@ > #include "php_incomplete_class.h" > > #define COMMON ((*struc)->is_ref ? "&" : "") > +#define Z_REFCOUNT_PP(a) ((*a)->refcount) > > /* }}} */ > /* {{{ php_var_dump */ > @@ -112,6 +113,7 @@ > /* }}} */ > > > + > /* {{{ proto void var_dump(mixed var) > Dumps a string representation of variable to output */ > PHP_FUNCTION(var_dump) > @@ -130,6 +132,102 @@ > > for (i=0; i<argc; i++) > php_var_dump(args[i], 1 TSRMLS_CC); > + > + efree(args); > +} > +/* }}} */ > + > +/* {{{ zval_debug_dump */ > + > +static int zval_array_element_dump(zval **zv, int num_args, > va_list args, zend_hash_key *hash_key) > +{ > + int level; > + 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 */ > + php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', > hash_key->arKey); > + } > + php_zval_debug_dump(zv, level + 2 TSRMLS_CC); > + return 0; > +} > + > +void php_zval_debug_dump(zval **struc, int level TSRMLS_DC) > +{ > + HashTable *myht; > + > + if (level > 1) { > + php_printf("%*c", level - 1, ' '); > + } > + > + switch (Z_TYPE_PP(struc)) { > + case IS_BOOL: > + php_printf("%sbool(%s) refcount(%u)\n", COMMON, > Z_LVAL_PP(struc)?"true":"false", Z_REFCOUNT_PP(struc)); > + break; > + case IS_NULL: > + php_printf("%sNULL refcount(%u)\n", COMMON, > Z_REFCOUNT_PP(struc)); > + break; > + case IS_LONG: > + php_printf("%slong(%ld) refcount(%u)\n", COMMON, > Z_LVAL_PP(struc), Z_REFCOUNT_PP(struc)); > + break; > + case IS_DOUBLE: > + php_printf("%sdouble(%.*G) refcount(%u)\n", COMMON, > (int) EG(precision), Z_DVAL_PP(struc), Z_REFCOUNT_PP(struc)); > + break; > + case IS_STRING: > + php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc)); > + PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc)); > + php_printf("\" refcount(%u)\n", Z_REFCOUNT_PP(struc)); > + break; > + case IS_ARRAY: > + myht = Z_ARRVAL_PP(struc); > + php_printf("%sarray(%d) refcount(%u){\n", COMMON, > zend_hash_num_elements(myht), Z_REFCOUNT_PP(struc)); > + 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)); > +head_done: > + zend_hash_apply_with_arguments(myht, > (apply_func_args_t) zval_array_element_dump, 1, level); > + if (level > 1) { > + php_printf("%*c", level-1, ' '); > + } > + PUTS("}\n"); > + break; > + case IS_RESOURCE: { > + char *type_name; > + > + type_name = > zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC); > + php_printf("%sresource(%ld) of type (%s) > refcount(%u)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name > : "Unknown", Z_REFCOUNT_PP(struc)); > + break; > + } > + default: > + php_printf("%sUNKNOWN:0\n", COMMON); > + break; > + } > +} > + > +/* }}} */ > + > +/* {{{ proto void zval_debug_dump(mixed var) > + Dumps a string representation of an internal zend value to output. */ > +PHP_FUNCTION(zval_debug_dump) > +{ > + zval ***args; > + int argc; > + int i; > + > + argc = ZEND_NUM_ARGS(); > + > + args = (zval ***)emalloc(argc * sizeof(zval **)); > + if (ZEND_NUM_ARGS() == 0 || > zend_get_parameters_array_ex(argc, args) == FAILURE) { > + efree(args); > + WRONG_PARAM_COUNT; > + } > + > + for (i=0; i<argc; i++) > + php_zval_debug_dump(args[i], 1 TSRMLS_CC); > > efree(args); > } > > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.cvs (#9337) next »