468,119 Members | 1,911 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

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

Hi,

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
string.)

Jarle
--
Jarle Aase http://www.jgaa.com
mailto:jg**@jgaa.com

<<< no need to argue - just kill'em all! >>>
Nov 23 '06 #1
1 2033
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 (php.net/spl).

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:
Hi,

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
string.)

Jarle
--
Jarle Aase http://www.jgaa.com
mailto:jg**@jgaa.com

<<< no need to argue - just kill'em all! >>>
Nov 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tony Johansson | last post: by
10 posts views Thread by Jay Wolfe | last post: by
5 posts views Thread by Sandman | last post: by
1 post views Thread by Rahul | last post: by
16 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.