473,414 Members | 1,691 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,414 software developers and data experts.

Variable scoping - issues with global and multiple includes

Hi All, Sorry if I'm just repeating other questions, but I can't find
an answer for this particular problem: I have my main index.php file,
which looks so: <?php include "includes/header.php"; #defines a global
variable called $lang include "includes/functions.php"; # some required
functions safe_include "main_page.html"; # user-defined function that
tries to # include main_page.html.$lang
or gives a warning message echo "Language available to index.php at
line XYZ is -$lang-"; #-- to check empty value include
"includes/footer.php"; #page footer ?> and header.php looks so: <?php
global $lang; $lang = "en"; ?> footer.php looks like so: <?php echo
"Language is set to -$lang-"; # should print out current language in
use ?> Now the problem is, the $lang variable is available to all
statements in between, upto and including the safe_include statement.
Unfortunately, footer.php refuses to see the variable. What can be
the problem? Thanks Hrishikesh

Apr 10 '06 #1
2 1479
argh! stupid gmail posting system that kills formatting !!!

Reformatted, here is my original query:

Hi All,

Sorry if I'm just repeating other questions, but I can't find an answer
for this particular problem:

I have my main index.php file, which looks so:

<?php

include "includes/header.php"; #defines a global variable called $lang

include "includes/functions.php"; # some required functions

safe_include "main_page.html"; # user-defined function that tries to

# include main_page.html.$lang or gives a
warning message

echo "Language available to index.php at line XYZ is -$lang-";

include "includes/footer.php"; #page footer

?>

and header.php looks so:
<?php
global $lang;
$lang = "en";
?>

footer.php looks like so:
<?php
echo "Language is set to -$lang-";
?>

Now the problem is, the $lang variable is available to all statements
in between, upto and including the safe_include statement.

Unfortunately, footer.php refuses to see the variable. What can be the
problem?

Thanks Hrishikesh

Apr 10 '06 #2
On 2006-04-10, hr******************@gmail.com <hr******************@gmail.com> wrote:
Now the problem is, the $lang variable is available to all statements
in between, upto and including the safe_include statement.

Unfortunately, footer.php refuses to see the variable. What can be the
problem?


You must have unset it somewhere. Otherwise it would still exist.

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Apr 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eyal Lotem | last post by:
Python has a few issues many consider problems with regard to its variable namespacing. It seems that the local/global/builtins namespacing rules are ancient remnants of a different Python. ...
8
by: It's me | last post by:
This must be another newbie gotchas. Consider the following silly code, let say I have the following in file1.py: #============= import file2 global myBaseClass myBaseClass =...
4
by: No One | last post by:
Is there any mechanism in an ASP.Net application to scope components? I know that forms and the like are set to a request scoping and that is fine, but there are certain components I need to have...
41
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
8
by: Florian Daniel Otel | last post by:
Hello all, As the subject says, I am a newcomer to Python and I have a newcomer question wrt namespaces and variable scope. Obviously, I might be missing smth obvious, so TIA for the patience...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
2
by: ray | last post by:
Hi, all, foreach($array as $k =$v) { $foo = ...; } echo $foo; Is it allowed to access the $foo variable that is created within the loop from outside of the loop? I think it isn't allowed,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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...

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.