473,746 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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**@jga a.com

<<< no need to argue - just kill'em all! >>>
Nov 23 '06 #1
1 2318
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**@jga a.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
3221
by: A | last post by:
Hi, Consider this code: //Header File - Foo.h int i = 0; // non-static global variable class Foo{ ...
2
519
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 Test testobj main() {}
4
9266
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 thing I'm talking about is easy to remember names for numerics values that have a particular significance in the application e.g. When I was using JScript.
0
1589
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, Laimis
10
7030
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, including main.cpp I have global variables that need defining in main.cpp and declaring in all other files in. The way I've seen it done is to define/declare everything in one header file (e.g. globalincludes.h) prefaced with the word EXTERN ...
5
11824
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 $MYVAR, $a; ?>
1
29372
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 called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
1
366
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 does that mean that the memory of the variable is allocated in BSS (data segment meant for static global variables) when the program is loaded and is available until the program is killed.
25
120668
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
8975
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8801
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9516
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9351
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9286
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9219
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8229
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6774
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
3
2200
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.