Re: trying to understand zvals

From: Date: Thu, 17 Oct 2002 15:31:30 +0000
Subject: Re: trying to understand zvals
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-89660@lists.php.net to get a copy of this message
TDJ>> Sorry, I wasn't clear. I mean ref_assign to be a C function, in my TDJ>> extension. Ah. Then you need to accept the first parameter by reference (this is defined in ZEND_FE definition, put first_arg_force_ref as second parameter). Then you get parameters the usual way (zend_get_parameters_ex, etc.) and have to zval ** variables, something like this: zval **dest, src; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dest, &src)) { WRONG_PARAM_COUNT; } Then if src wasn't reference, you need to separate it: SEPARATE_ZVAL_TO_MAKE_IS_REF(src); (*src)->refcount++; This will also make src a reference. Then you have to free old value of dest: zval_ptr_dtor(dest); Then assign: *dest = *src; I think this should be enough... Note that refcount is increased before calling dtor - to avoid problems with something like assign_ref($foo, $foo) (it's not wise to do this, but this way it won't crash/produce garbage). -- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.109

« previous php.dev (#89660) next »