Re: Modifying PHP variables in C

From: Date: Tue, 04 Mar 2003 17:05:15 +0000
Subject: Re: Modifying PHP variables in C
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-94768@lists.php.net to get a copy of this message
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" <heyjohnlim@yahoo.com> 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

« previous php.dev (#94768) next »