Q1: "how to modify this line to reproduce the behavior of PHP"
A1:
/* {{{ vendor_my_get_debug_info */
static HashTable*
vendor_my_get_debug_info(zend_object *object, int *is_temp)
{
vendor_my *intern = ZOBJ_TO_VENDOR_MY(object);
HashTable *debug_info=NULL, *std_props=NULL;
*is_temp = 1;
std_props = zend_std_get_properties(object);
debug_info = zend_array_dup(std_props);
zval zdata;
if (Z_ISREF(intern->data) && Z_REFCOUNT(intern->data)<2) {// If
the reference is no longer used by the PHP-user
ZVAL_COPY(&zdata, &Z_REF(intern->data)->val);// hide reference
(for compatibility)
} else {
ZVAL_COPY(&zdata, &intern->data);// show reference (for debugging ???)
}
zend_hash_str_update(debug_info, "data", sizeof("data")-1, &zdata);
return debug_info;
} /* }}} */
Q2: "Why do I have to hide that it's a reference ?"
A2: For historical( debugging) raison, see :
https://github.com/php/php-src/blob/master/ext/standard/var.c#L202
I think it's a bad idea to show & but it doesn't really matter.
In my case I think it's best never to show the reference :
zval zdata; ZVAL_COPY(&zdata, Z_ISREF(intern->data) ?
&Z_REF(intern->data)->val : &intern->data);
zend_hash_str_update(debug_info, "data", sizeof("data")-1, &zdata);
If I need to debug references/refcount it is better to use gdb's
pretty-print feature but no var_dump()
Le sam. 9 avr. 2022 à 17:51, Glash Gnome <glash.gnome@gmail.com> a écrit :