PHP check variable function?
<p>I'm trying to write a function to check if my variables are valid. For example, in my script I have:  </p>

<pre><code>$flag = $_GET['page'];
</code></pre>

<p>But then I get the error: </p>

<pre><code>Notice: Undefined index: page in C:\xampp\htdocs\phpinv\php\add.php on line 8
</code></pre>

<p>I tried writing a checkVar function:</p>

<pre><code>function checkVar($var, $method, $defaultValue){
    if (!isset($method['$var'])) 
    {
        $var = $defaultValue;
    } else {
        $var = $method['$var'];
    }
}
</code></pre>

<p>But then I get:</p>

<pre><code>Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\phpinv\php\functions.php on line 21
</code></pre>
