For example, if I put this code in a file called globaltest.php:
$new_var="This is a string";
class TestClass
{
function __construct()
{
global $new_var;
echo "<br>new var: ".$new_var;
}
function testFunc()
{
global $new_var;
echo "<br>new var in testFunc(): ".$new_var;
echo "<br>from globals ".$GLOBALS['new_var'];
}
}
$testo=new TestClass();
$testo->testFunc();
It displays
new var: This is a string
new var in testFunc(): This is a string
from globals This is a string
as it should.
However, when I put it in another file that is an included php file, it
doesn't even register new_var as a global, and I get this printed out:
new var:
new var in testFunc():
from globals
I don't understand. What could possibly be making this happen? Right
now I am looking for any possibilities, because to me, it doesn't seem
to make sense.
I am using 5.0.4, but, the same happens in 5.0.5 2 1301 www.douglassdavis.com wrote: For example, if I put this code in a file called globaltest.php:
$new_var="This is a string";
class TestClass {
function __construct() { global $new_var; echo "<br>new var: ".$new_var; }
function testFunc() { global $new_var; echo "<br>new var in testFunc(): ".$new_var; echo "<br>from globals ".$GLOBALS['new_var']; } }
$testo=new TestClass(); $testo->testFunc();
It displays
new var: This is a string new var in testFunc(): This is a string from globals This is a string
as it should.
However, when I put it in another file that is an included php file, it doesn't even register new_var as a global, and I get this printed out:
new var: new var in testFunc(): from globals
I don't understand. What could possibly be making this happen? Right now I am looking for any possibilities, because to me, it doesn't seem to make sense.
Are you including the include file in the global scope, outside of any
classes/methods?
Are you defining the variable you are attempting to access in the global
scope as well?
Post the code that doesn't work, not the one that does.
Carl. I am using 5.0.4, but, the same happens in 5.0.5
Carl wrote: Are you including the include file in the global scope, outside of any classes/methods? Are you defining the variable you are attempting to access in the global scope as well? Post the code that doesn't work, not the one that does.
Carl.
that's the code that doesn't work. It doesn't work when included, does
work when it is in a standalone file.
But thanks for the help... I thought i had included it from the global
scope, but, turns out i had included it from another scope previously
some where else in the code. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: kevin bailey |
last post by:
this old script was written when
register globals was 'on'.
now i need to convert it to run on a server with a php 4.3.6 - do i just
convert the relevant variables from
$posted_variable to...
|
by: John |
last post by:
Hi,
I'm looking for the best way to deal with globals in PHP.
As a 'C' software developer, I would normally avoid all
globals and not have any at all, but use structs and pass
everything in...
|
by: Ron |
last post by:
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'left'
<%
set objFSO = CreateObject("Scripting.FileSystemObject")
|
by: greenflame |
last post by:
I have been working for some time on a script that will show a matrix
with the elements aligned on the right for sometime and finally got it
to work. Then I did some patching up and ran the script...
|
by: J Sahoo |
last post by:
Hi,
I have a browse page where I am showing few fields from my SQL Server
table. One of the field is Image type, all the fields are bound to a
single table.
I want to show the image from the...
|
by: bridgemanusa |
last post by:
Hi All:
I have a very long page of html that I want to take portions and hide
them in divs, then show when a link is clicked. I have the hide show
part working when the link is clicked, however...
|
by: ABC |
last post by:
I want click a button and than to popup window which will show my one PDF
file. How should I to coding in C#?
|
by: Franky |
last post by:
In a prior post I asked about referencing the folder "My Documents"
and someone was good enough to tell me about:
SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL, 0,
szMyDocPath);...
|
by: briankind |
last post by:
Hello
i have these radio buttons and i wish to have the corresponding textboxes to be visible when the radiobutton is selected.
any Help?
snippets.
thanks
thanks in adv
Bry
|
by: deerchao |
last post by:
I set ListView.Dock to Top, but how can I get the desired height to
avoid it to show vertical scrollbar?
I mean is there something like ListView.ClientSize or
ListView.VirtualHeight?
Thanks!
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |