Why is it a good programming practise to check whether a value exists before using it?
<p>Suppose using a isset() function, we checked whether an ID  did exist or the user did submit an ID, before assigning it to variables or using it some place in the code that follows.</p>

<pre><code>     &lt;?php

        if(isset($_GET['Id']))
    {

     $Id=$_GET['Id'];
    }
?&gt;
</code></pre>

<p>Now I understand, it's good to do this </p>

<p>1)So the code as per the expected behavior i.e. does what it's expected to accomplish. For Example -  if id was going to be used in some query which would return a row based on that id, it's always a good idea to provide a valid id to be sure that the query indeed returns a row as a result... This avoids the unexpected behavior that the query fails if it wasn't provided with a valid id.</p>

<p>2)And as obvious, minimizing any runtime errors that our code might generate.</p>

<p>So, I'm looking for more relevant examples and context as to why this is always a good programming practise.</p>

<p>Basically more examples to help me sink in my understanding why it's really good to do so ... Many Thanks.</p>
