473,386 Members | 1,712 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.

Ignoring Undefined Variables

When I run PHP scripts on my company's web server, I can attempt to read a
variable that has not already been declared.

When I try to access a variable before a value is assigned on my home
computer (Windows with IIS), I get a warning about the variable being
undefined.

Is there a flag in php.ini that allows a script to check a variable before
defining it?
Jul 17 '05 #1
4 3689
>When I run PHP scripts on my company's web server, I can attempt to read a
variable that has not already been declared.

When I try to access a variable before a value is assigned on my home
computer (Windows with IIS), I get a warning about the variable being
undefined.
Careful use of isset() on every variable that might be undefined
before trying to use its value will avoid this. Most any element
of $_GET, $_PUT, $_COOKIE, $_SERVER, etc. should be considered as
possibly undefined until proven otherwise. How you handle an
undefined variable is up to you: give it a default, skip the section
dealing with it entirely, display an error back to the user, or
whatever.
Is there a flag in php.ini that allows a script to check a variable before
defining it?


As far as I know, nothing in php.ini is required to use isset().

IMHO, you should consider each warning as a bug that needs to be fixed.
You should use error_reporting(E_ALL) on your company's server to
get the warnings.

Gordon L. Burditt
Jul 17 '05 #2

"Pizzor2000" <ex******@att.net> wrote in message
news:M0*********************@bgtnsc05-news.ops.worldnet.att.net...
When I run PHP scripts on my company's web server, I can attempt to read a
variable that has not already been declared.

When I try to access a variable before a value is assigned on my home
computer (Windows with IIS), I get a warning about the variable being
undefined.

Is there a flag in php.ini that allows a script to check a variable before
defining it?


What you're getting are notices, not warnings. Just set error_reporting to
exclude E_NOTICE and they'll be gone.
Jul 17 '05 #3
.oO(Chung Leong)
What you're getting are notices, not warnings. Just set error_reporting to
exclude E_NOTICE and they'll be gone.


It would be better to fix the issues instead.

Micha
Jul 17 '05 #4
"Michael Fesser" wrote:
.oO(Chung Leong)
What you’re getting are notices, not warnings. Just set

error_reporting to
exclude E_NOTICE and they’ll be gone.


It would be better to fix the issues instead.

Micha


Agreed. More error/warnings are always better than less. Use isset
to check for a variable being defined, like this:
if (isset($a) && $a == ’something’) ... do something

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Ignoring...ict138888.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=464415
Jul 17 '05 #5

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

Similar topics

6
by: Will | last post by:
I downloaded a webcounter from http://www.math.sunysb.edu/~shafikov/computing/webcounter. It seems to be working but I have the following being printed to the page: Notice: Undefined variable:...
3
by: Jason | last post by:
hello, i am new to PHP, so go easy. I am using the examples in the book: PHP: Your Visual Blueprint For Creating Open Source, Server Side Content In the section where they talk about...
0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
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...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
6
by: tshad | last post by:
I have a structure (which happens to be a Java DataBean that contains some string arrays) that is giving me an error. The error at the "for" statement is: Object reference not set to an...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
1
by: yamitmehta | last post by:
When I compile to code using g++arm of VxWorks 5.5 and put it on my board i get the follwing undefined symbols:- Cpool and Csingleton are template classes. CPool has the static member...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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.