Re: Undefined variables
| From: | Phil Driscoll | Date: | Thu, 02 Nov 2000 11:28:26 +0000 |
| Subject: | Re: Undefined variables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-23369@lists.php.net to get a copy of this message | ||
>for those who work with IIS 5, like me, how to prevent the error:
>
>Warning: Undefined variable in line...
>
>if using the variable for the first time?
Nothing to do with IIS!
You only get the warning when you use a variable for the first time in the
right hand side of an expression.
e.g.
If the first line of your code is:
$X=$Y
php will complain that $Y is undefined (and will give it a value of 0)
However if you go
$Y=1;
$X=$Y;
you will get no warning.
Sometimes you may be expecting $Y to be passed in to php as a GPC variable,
in which case you can go:
if(!isset($Y))$Y=0;//or some other sensible default value
$X=$Y;
Hope this helps.
Cheers
--
Phil Driscoll
Dial Solutions
+44 (0)113 294 5112
http://www.dialsolutions.com
http://www.dtonline.org