473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 2292
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: A | last post by:
Hi, Consider this code: //Header File - Foo.h int i = 0; // non-static global variable class Foo{ ...
2
by: Tony Johansson | last post by:
Hello experts! Is it any difference if I instansiate object testobj of class Test as alternative (1) or (2). In this case I think it's the same thing. I'm I right. (1)Test testobj (2) static...
4
by: Grant Ord | last post by:
You gather I'm new to C#... I'm used to declaring global variables and application constants in a common script file in ASP apps but now in I'm sure things are done differently. The sort of...
0
by: lnd | last post by:
What is the best method to implement pgplsql global variables with "per connection"(i.e. session) scope? (one way is to use temporary tables - but isn't it overkill?) Thank you in advance,...
10
by: Jay Wolfe | last post by:
Hello, I'm trying to make sure I use best practices (and hence save myself some headaches) with the declaration and definition of global variables. Let's say I have an app with 30 files,...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
1
by: Rahul | last post by:
Hi Everyone, It is known that static member variables can be accessed without creating an instance of the class and it serves as a global variable without polluting the global name space. So...
25
by: shadyabhi | last post by:
I heard that all global variables are static.. If its so then what is the difference between the 2 declarations: #include<stdio.h> int a; static int b; main()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.