I'm trying to write a function to check if my variables are valid. For example, in my script I have:
$flag = $_GET['page'];
But then I get the error:
Notice: Undefined index: page in C:\xampp\htdocs\phpinv\php\add.php on line 8
I tried writing a checkVar function:
function checkVar($var, $method, $defaultValue){
if (!isset($method['$var']))
{
$var = $defaultValue;
} else {
$var = $method['$var'];
}
}
But then I get:
Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\phpinv\php\functions.php on line 21
$varis not a reference and yet the function is not returning anything.