Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3692 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30482 invoked from network); 1 Aug 2003 22:10:28 -0000 Received: from unknown (HELO mail.zend.com) (192.117.235.230) by pb1.pair.com with SMTP; 1 Aug 2003 22:10:28 -0000 Received: (qmail 6117 invoked from network); 1 Aug 2003 22:10:27 -0000 Received: from localhost (HELO zeev-laptop.zend.com) (127.0.0.1) by localhost with SMTP; 1 Aug 2003 22:10:27 -0000 Reply-To: zeev@zend.com Message-ID: <5.1.0.14.2.20030802010413.088ccd70@localhost> X-Sender: zeev@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Sat, 02 Aug 2003 01:16:46 +0300 To: Ken Spencer Cc: internals@lists.php.net In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] Making a variable global question From: zeev@zend.com (Zeev Suraski) References: At 03:44 01/08/2003, Ken Spencer wrote: >I am trying to make a function for my extension that makes a predefined >variable global > >I have tried something along the lines of: > > if(zend_hash_find(&EG(symbol_table), var, strlen(var)+1, (void **) > &vars_data)!=FAILURE) >{ > ZEND_SET_SYMBOL(EG(active_symbol_table), var, *vars_data); >} You're messing with the reference count here. ZEND_SET_SYMBOL() 'takes over' this zval, and the original copy becomes corrupted. That's probably why it fails the second time you try it. You need to use ZEND_SET_SYMBOL_WITH_LENGTH() instead, and take care of the reference count manually. When touching a zval coming back from an engine-controlled symbol table, you must take care of the reference count (in this case, increment it). If you want the two variables to be references, that is, changing one would change the other - you should also turn on the is_ref bit, and not forget to first separate it. It should look something like this: if(zend_hash_find(&EG(symbol_table), var, strlen(var)+1, (void **) &vars_data)!=FAILURE) { SEPARATE_ZVAL_IF_NOT_REF(vars_data); (*vars_data)->refcount++; ZEND_SET_SYMBOL_WITH_LENGTH(EG(active_symbol_table), var, strlen(var)+1, *vars_data, (*vars_data)->refcount, 1); } Zeev