Re: [PECL-DEV] myext_globals->global_value vs MYEXT_G(global_value)

[email protected] ("Gustavo Lopes")
Newsgroups php.pecl.dev
Organization Núcleo de Eng. Biomédica do IST
Message-ID <[email protected]>
On Thu, 05 Aug 2010 02:23:05 +0100, j adams <[email protected]> wrote:

> I am wondering about the correct way to deal with global vars when
> writing a PECL extension.

I wrote about this a while back in the wiki.
See http://wiki.php.net/internals/engine#extension_globals

>
> And then initialized in a function I have not yet seen documented in
> any of the 'getting started' materials:
> /* {{{ PHP_GINIT_FUNCTION
> */
> static PHP_GINIT_FUNCTION(json)
> {
>     json_globals->error_code = 0;
> }
> /* }}} */
>
> This json_globals->error_code assignment puzzles me for two reasons.
>
> First, what is this PHP_GINIT_FUNCTION?

It's just a legacy name of ZEND_MODULE_GLOBALS_CTOR_D (I say "legacy"  
because there's a comment saying "for compatibility" before the macro is  
defined).

> It seems to me that a last_error type var should be initiated in a
> MINIT function, no?

I think it's more or less indifferent, but the globals constructor is  
called before the module startup function (and the module shutdown is  
called before the globals destructor).

-- 
Gustavo Lopes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.