Stanislav Malyshev <[EMAIL PROTECTED]> 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

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to