Ignoring Undefined Variables

This is a discussion on Ignoring Undefined Variables within the PHP Language forums, part of the PHP Programming Forums category; When I run PHP scripts on my company's web server, I can attempt to read a variable that has ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-12-2004
Pizzor2000
 
Posts: n/a
Default 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?


Reply With Quote
  #2 (permalink)  
Old 08-12-2004
Gordon Burditt
 
Posts: n/a
Default Re: 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.


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
Reply With Quote
  #3 (permalink)  
Old 08-12-2004
Chung Leong
 
Posts: n/a
Default Re: Ignoring Undefined Variables


"Pizzor2000" <extranms@att.net> wrote in message
news:M0ASc.198979$OB3.148018@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.


Reply With Quote
  #4 (permalink)  
Old 08-12-2004
Michael Fesser
 
Posts: n/a
Default Re: Ignoring Undefined Variables

.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
Reply With Quote
  #5 (permalink)  
Old 08-12-2004
steve
 
Posts: n/a
Default Re: Re: Ignoring Undefined Variables

"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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0