471,090 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,090 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 3557
>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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Will | last post: by
49 posts views Thread by matty | last post: by
17 posts views Thread by yb | last post: by
6 posts views Thread by tshad | last post: by

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.