Accessing the global symbol table from internal functions (PHP 4.0 only)
| From: | Zeev Suraski | Date: | Fri, 30 Jul 1999 04:08:53 +0000 |
| Subject: | Accessing the global symbol table from internal functions (PHP 4.0 only) | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-9341@lists.php.net to get a copy of this message | ||
The information here applies to PHP 4.0 only.
I've just updated the various SET_VAR_*() macros to support references. That means that from now on, if you set the global variable $foo, and $foo is a reference to $bar, then your update will modify both $foo and $bar (until now, it separated $foo from $bar, only $foo was set to the new value, and $foo and $bar were no longer referencing each other).
That means you must no longer directly update the main symbol table (EG(symbol_table)) from anywhere but infrastructure code (read: pretty much nowhere). Nothing 'bad' would happen if you do (that is, PHP won't crash or anything) - but it'll present the old behavior.
If you want to update the main symbol table not using the SET_VAR_*() macros (usually if you generate the pval's yourself), you can use one of the following macros:
ZEND_SET_GLOBAL_VAR(name, var)
ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var)
name is a char *, var is a zval *, and name_length (if applicable) is its length (including the terminating NULL!).
When you use these macros, you're no longer responsible for maintaining the Zend status flags and counters - the reference count (.refcount), the reference status bit (.EA.is_ref) and the lock count (.EA.locks) - the macros takes care of them for you - in other words, there's no reason to call INIT_PZVAL() if you use these macros.
Sascha - what triggered me to do it was a bug report from Ivan Schreter, that complained that the session module was updating variables in the global scope, but these weren't being reflected in variables he declared as 'global'. This should fix it - if you move to use these new macros...
Zeev
--
Zeev Suraski <zeev@zend.com> http://www.zend.com/
For a PGP public key, finger bourbon@netvision.net.il