This is another fine example of the lack of explicit definitions in Beginning PHP 4. When the book was issued the PHP group had not yet changed the error reporting directive in php.ini to E_ALL by default, showing all errors and notices including undefined variables and well a multitude of what may seem like a very strict way of writing PHP code. Instantly tightening up PHP's previously very loose way of interpretting code which Beg. PHP 4 relied very heavily on.
Using isset() which checks for a variable's existence and empty() which checks for null value is much, much better than simply going into a statement. The use of these functions is also very handy for tracking down bugs~!
Consider this example
if ($foo) {
#Execute code relying on the existence and non-empty value of $foo
}
Well if you write a statement like this:
$foo = false;
$foo now contains a false value but would still be considered null, and the above statement would not execute.
Now you would want to use:
if (isset($foo)) {
#Execute code which rely's on $foo's existence but not its value
if (empty($foo)) {
#If $foo contains an empty, null, zero, or false boolean value... execute this code
}
# Other statements relying on the existence of $foo
}
The undefined variable warning basically means that you need to explicitly set $foo's value before it may be compared or used in any context.
This is good because most every other language that exists requires an explicit variable declaration before the variable may be used. And again in the long run you will find that this will aid in the alleviation of errors and be a fantastic tool in the debugging process.
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::