unset a reference of property object
| From: | Glash Gnome | Date: | Sat, 09 Apr 2022 13:42:11 +0000 |
| Subject: | unset a reference of property object | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-117507@lists.php.net to get a copy of this message | ||
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