473,811 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Var will not show up in globals!!??

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

Oct 11 '05 #1
2 1324
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

Oct 11 '05 #2

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.

Oct 11 '05 #3

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

Similar topics

12
2689
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 $_POST i realise that many of the variables are internal to the scrit so will not
7
1762
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 the function parameters... However, being realistic, I can see that globals can (and do ?) have a place in PHP web scripts.
2
2916
by: Ron | last post by:
Microsoft VBScript runtime error '800a0005' Invalid procedure call or argument: 'left' <% set objFSO = CreateObject("Scripting.FileSystemObject")
6
1785
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 and it showed a blank page and no error in the status bar. The script is rather long and I call functions that do things that I may not need the functiosn for but they are there because I so that task so many times that I jsut made it into a...
2
2700
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 table on this browse along with the other fields. Here is the code what I have from the HTML view, I am using a datagrid to show the result. It does not show the image rather it shows "System.Byte " on the output. I did not have any code behind...
4
4234
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 I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is swapped with close.gif - subsequently, when close.gif is clicked, the div contents get hidden
3
11181
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#?
8
2750
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); But now I think I asked the wrong question. What I want is a folder into which I can put a folder that will show in everyone's MyDocuments.
11
22878
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
1
2175
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!
0
9722
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
10379
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
10393
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
10124
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
9200
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
7664
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...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.