You should use zval_ptr_dtor() to dispose the old value. Note the old value won't actually be freed as long as any reference to the variable is alive.
for example, zval *ary1, *ary2; /* $ary1 = array(); */ ALLOC_INIT_ZVAL(ary1); array_init(ary1); /* $ary2 = array(); */ ALLOC_INIT_ZVAL(ary2); array_init(ary2); /* $ary1['key'] = 123; */ add_assoc_long_ex(ary1, "key", sizeof("key"), 123); /* $ary2['key'] = 456; */ add_assoc_long_ex(ary2, "key", sizeof("key"), 456); /* $ary1 = $ary2 */ zval_add_ref(ary2); zval_ptr_dtor(&ary1); ary1 = ary2; Moriyoshi "John Lim" <[EMAIL PROTECTED]> wrote: > Hi, > > I'm porting some PHP code to C, and was hoping that someone can help me. > > I have 2 variables $oldarray and $newarray that both hold arrays and want > to set > > $oldarray = $newarray; > > I suppose i have to dispose of $oldarray before i set it to $newarray. I'm > not sure what is the best way, so i did this. > > zval **oldarray,*newarray; > > zval_add_ref(&newarray); > convert_to_null_ex(oldarray); > *oldarray = newarray; > > Would this work? Secondly is there a better way. Thanks again. > > John Lim -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php