Out of politeness I answer myself,

PHP_FUNCTION(var_dump)
 -> php_var_dump()
     -> zend_std_get_properties_for() //                     Zend
object handler get_properties_for
         -> obj->handlers->get_debug_info(obj, &is_temp); // Zend
object handler get_debug_info
             -> zend_std_get_properties();//                 Zend
object handler get_properties
                 -> rebuild_object_properties()
                     -> _zend_hash_append_ind()
                         => ZVAL_INDIRECT(&p->val, ptr); // do the
trick( Z_TYPE change)
TODO: Find out how to manage the IS_INDIRECT

So to reproduce the default php behavior I can implement the
get_debug_info handler.

I'm still trying to figure out how to modify this line :
void my_get_debug_info() {
    // ...
    // Z_REFCOUNT(intern->data)==1
    // Z_TYPE(intern->data)==IS_REFERENCE
    // Z_TYPE(Z_REF(intern->data)->val)==IS_ARRAY
    zval zdata; ZVAL_COPY(&zdata, &intern->data);// Why do I have to
hide that it's a reference ?
    zend_hash_str_update(debug_info, "data", sizeof("data")-1, &zdata);
    // ...
    return debug_info;
}

my_handlers.get_debug_info = my_get_debug_info;


struct _my {// intern structure
    zval data;// array of unsigned int
    zend_object std;
};

Le sam. 9 avr. 2022 à 15:42, Glash Gnome <glash.gn...@gmail.com> a écrit :

> Hello,
>
> I am developing a PHP extension. I can't reproduce the behavior of
> references of Zend/PHP.
>
> Here is some Code illustrating Zend's behavior:
> <?php
> class Foo { public $baz = array(1);}
> $foo = new Foo();
> $ref = &$foo->baz;
> $foo->baz = [123];//set array has reference
> var_dump($foo);
>
> Output ------------------------
> object(Foo)#1 (1) {
> ["baz"]=>
> &array(1) { [0]=> int(123) }
> }
> --------------------------------
> Note the symbol ( &) output from the var_dump();
>
>
> Now I add unset($ref) in my code
> <?php
> class Foo { public $baz = array(1);}
> $foo = new Foo();
> $ref = &$foo->baz;
> //unset($ref);// kill reference
> $foo->baz = [123];// set array has reference
> unset($ref) ;// kill reference
> var_dump($foo);
> ------------------------
> object(Foo)#1 (1) {
> ["baz"]=>
> array(1) { [0]=> int(123) }
> }
> --------------------------------
>
> Note that the symbol (&) has disappeared from the output of var_dump();
>
> I would like to reproduce this behavior but I don't know which method of
> zend_object_handlers allows to remove( Z_UNREF) the reference.
>
> Thank you for your help
>
>
>

Reply via email to