Re: trying to understand zvals

From: Date: Thu, 17 Oct 2002 16:46:29 +0000
Subject: Re: trying to understand zvals
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-89671@lists.php.net to get a copy of this message
Stanislav Malyshev <stas@zend.com> writes: > 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: Thanks for your response! While it does not cause a crash, your function doesn't do what I expected. Do you know where I went wrong? This script: <? if(!extension_loaded('foo')) { dl('foo.so'); } //make two variables $foo = "foo"; $bar = "zonk"; //reference assignment stas_ref_assign($bar, $foo); //should be identical echo "$foo\n"; echo "$bar\n"; //set foo and bar to "baz" $bar = "baz"; //should print "baz" echo "$foo\n"; ?> Outputs "foo zonk foo", and I expected "foo foo baz". I made the following function: PHP_FUNCTION(stas_ref_assign) { zval **dest, **src; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dest, &src)) { WRONG_PARAM_COUNT; } SEPARATE_ZVAL_TO_MAKE_IS_REF(src); (*src)->refcount++; zval_ptr_dtor(dest); *dest = *src; } with the function entry: PHP_FE(stas_ref_assign, first_arg_force_ref) Thanks, -Tim

« previous php.dev (#89671) next »