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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
>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 |
|
|||
|
"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. |
|
|||
|
"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 |