Best way to implement static global variables (in an extension)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I wrote a multilanguage cms system a few years ago. Different languages are  
handled by loading php-files where each language-specific string is  
assigned to a normal php-variable ($LNG[] array).  

This loading takes place for each request.

Now I'm developing a backend server in C++ that will allow some better  
security-checking, session management and caching. The backend server has a  
companion php extension module.

I want to make as few changes in the .php files as possible. Several  
companies has used and extended the cms system, and if I change the cms's  
API, they will have to hire programmers to update their code.  

To make it easy to maintain the system, I want the language-texts to be  
stored in a MySQL database. I want the backend server to handle this table,  
and feed all the texts to the extension module when it starts up (one copy  
pr. process or in shared memory - that is not important).

So - my question is: How is the best way to implement static global  
variables in the extension module, without affecting the cms systems API?  
(Today the .php files use the $LNG[whatever] syntax to get a language text  

Jarle Aase      

<<< no need to argue - just kill'em all! >>>

Re: Best way to implement static global variables (in an extension)

If providing array-like access syntax is needed, you could use the
read_dimension handler in PHP5 to invoke your own custom lookup
function. This will allow you to access cached data any way you like.
The SPL's ArrayObject and ArrayIterator provides functionality which
you might be able to use as well (

You could also set a global array variable containing your strings in
your PHP_RINIT function. I don't know if you can allocate and fill the
array once in PHP_MINIT, and just re-reference it in PHP_RINIT with
ZEND_SET_SYMBOL... That would allow it to be cached.

Another option would be to convert $LNG[] to a function call with a
search-and-replace script.

I don't know much about PHP extensions... Maybe someone else can offer
some tips, or ask on the Zend lists?

Jarle Aase wrote:
Quoted text here. Click to load it

Site Timeline