Unless you define your function with a default value for you parameter, you should get an error.
It should produce an error anyway...
It depends on your error_reporting setting, if you are at E_ALL reporting it will cause an error if it is not set, lower error reporting levels may cause the error not to be shown but it will still be generated. You should never try to use a variable that doesn't exist or that you are not sure about, its bad coding practise. Use isset() to check for the variable, eg:
It depends on your error_reporting setting, if you are at E_ALL reporting it will cause an error if it is not set, lower error reporting levels may cause the error not to be shown but it will still be generated. You should never try to use a variable that doesn't exist or that you are not sure about, its bad coding practise. Use isset() to check for the variable, eg:
Or in one line:
I use something like:
PHP Code:
function myFunction ($val = false) {
if($val) {
return false;
} else {
return "Check out this: ".$var;
}
}
if($var = myFunction($_GET['foo'])) {
echo $var;
} else {
die('<b>Fatal : $_GET[\'foo\']</b> : Was not set');
}
I would however have the funcntion maybe return a error, or have the function die().
function myFunction ($val = false) { if($val) { return false; } else { return "Check out this: ".$val; } }
if($var = myFunction($_GET['foo'])) { echo $var; } else { die('<b>Fatal: $_GET[\'foo\']</b> : Was not set'); }
I would however have the funcntion maybe return a error, or have the function die().
After fixing your nested single quote (on the die() line), and the unset variable in the else{} section of the first function, Your code produces the following:
Code:
Notice: Undefined index: foo in C:\server\htdocs\icdsite\dev\noway.php on line 10
Check out this:
As I stated, you should never use unset variables before checking their existance, and you should always test your scripts in a high reporting state, you can put:
It should produce an error, I dont know about a fatal one though... Alot of "variable unset errors" are notices. To be honest, its just best to make sure a variable exists rather than trying to trick the parser.