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

Notice: Undefined variable and include files

I'm new to PHP - moving over from ASP.

I have a number of include files, the first of which sets the value of
a variable $loginmsg. I use that variable in a subsequent include
file, but get a "Notice: Undefined variable loginmsg" warning. I've
had a good look at previous posts concerning this warning, and see that
isset() is recommended to prevent this kind of warning. Is this
totally necessary?

In ASP, and include file becomes part of the total script for the page
that calls the include. Is this different in PHP? Is each include
treated as a separate script?

TIA

Mike

Oct 31 '05 #1
3 7621
I'm new to PHP - moving over from ASP. file, but get a "Notice: Undefined variable loginmsg" warning. I've


PHP variable names are case-sensitive. See
<http://www.php.net/manual/en/language.variables.php>.

---
Steve

Oct 31 '05 #2
>I've had a good look at previous posts concerning this warning, and see >that isset() is recommended to prevent this kind of warning. Is this totally >necessary?

isset() prevents the warning, but there's a bigger issue here. Not so
much caring whether the variable was set, but where it might have been
set. Suppose you include file inc1.php and he sets some variable.
Then later you include inc2.php. You can't really be sure that by the
time you get to inc2 the value of the variable is the same as it was
when you left inc1. Perhaps it shouldn't be if some other processing
occured, but this point leads into the next question:
In ASP, and include file becomes part of the total script for the page
that calls the include. Is this different in PHP? Is each include
treated as a separate script?


When you use include() or require(), you've effectively picked up any
code in that file and dropped it in where you call include(). That
means that the code in the included file lives in the same scope where
include() was called. For instance, suppose you had an include file
called inc1.php that contained the following:

<?
echo $foo;
?>

In your main script, you have something like this:

$foo = 5;

function bar($x) {
$foo = $x+1; //this foo is local to the function bar
include('inc1.php');
return $foo;
}

bar(1); //call the function

This will output 2. However, if you move the include() outside the
function declaration the script will output 5.

Nov 1 '05 #3
Mike wrote:
I'm new to PHP - moving over from ASP.

I have a number of include files, the first of which sets the value of
a variable $loginmsg. I use that variable in a subsequent include
file, but get a "Notice: Undefined variable loginmsg" warning. I've
had a good look at previous posts concerning this warning, and see that
isset() is recommended to prevent this kind of warning. Is this
totally necessary?


One thing to remember in PHP is that global variables are not
automatically availabe within functions.

Nov 1 '05 #4

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

Similar topics

10
by: PCHOME | last post by:
Hi! Would someone please help me thess C error(in gcc on Linux)? The compiler continues to give me: readLP.o: In function `Input_Problem': readLP.o(.text+0x0): multiple definition of...
8
by: pavan734 | last post by:
Hello, Please excuse me as Iam not posting this to correct group. I have a parser code obtained from flex command. I have many other files. When I compile them Iam getting a message like:...
1
by: prabhunew2005 | last post by:
hi I am doing web portal design using php. I gave part of one of my screen coding. <html> <head> <script language = "javascript"> function list_all_click()
1
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
2
by: Reggie | last post by:
am trying to create a a upload file.am uploading files ok but i recieve this message. Notice: Undefined variable: uploaded_size in /home/fhlinux169/c/ clashoff.co.uk/user/htdocs/upload.php on...
3
by: printline | last post by:
Can anyone help me with why i am getting this error message: Notice: Undefined variable: SalesRepID in C:\Inetpub\wwwroot\index.php on line 158 Here is my php code: <?php session_start();...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
0
by: newbie73 | last post by:
Going through the tutorial on http://swig.org, I created the example files (pasted below). After generating the _wrap file, I tried compiling (using mingw32) and received a lot of undefined...
1
by: francsutherland | last post by:
Notice: Undefined index: send in D:\Domains\workingdata.co.uk\wwwroot\contact_text.php on line 7 Hi, I've started getting this error in the contact page form of my website. The web hosting...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...

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.