title: PHP, does "else" always get processed?
body: <p>I have a rough program sketched thusly:</p>
  
  <pre><code>if (condition){
    //redirect to some page
  }
  else{
   echo $some_var;
  }
  </code></pre>
  
  <p>So when I test is and the condition is true, it does the redirect, but also throws notices that there are undefined variables $some_var (that are pulled from a DB and WON'T be defined if the condition is true).</p>
  
  <p>So does the code continue to evaluate after the if? This is not what I've expected.</p>
  
  <p>If you want to dig, here's the actual code (it's CodeIgniter, but it's mostly self-documenting) and the test case is a garbage "gift code" that's not in the DB, so that <code>count_all_results WILL == 0</code>.  The notices thrown are that $uses is undefined.</p>
  
  <pre><code>    $data['message'] = null;
  
      //seeing if code is valid
      $submitted_code = $_POST['code'];
      $this-&gt;db-&gt;where('code', $submitted_code);
      $this-&gt;db-&gt;from('codes');
      if ($this-&gt;db-&gt;count_all_results() == 0){
          $data['message'] = "This is not a valid gift code, sorry! You'll need to read our partner blogs, or listen to our favored Twitterers to find a valid code.";
          $this-&gt;load-&gt;view('submission_form_view', $data);
      }
      else {
  
      //seeing if code has any uses left
      $this-&gt;db-&gt;where('code', $submitted_code);
      $this-&gt;db-&gt;from('redemption_information');
      $used_so_far = $this-&gt;db-&gt;count_all_results();
      $this-&gt;db-&gt;select('uses');
      $query = $this-&gt;db-&gt;get_where('codes', array('code' =&gt; $submitted_code));
      foreach ($query-&gt;result() as $result)
      {
          $uses = $result-&gt;uses;
      }
  
      echo "Uses: $uses Used so far: $used_so_far &lt;br /&gt;";
  
      if ($uses &lt;= $used_so_far) {
          $this-&gt;load-&gt;view('over_used_view');
      }
      else
      {
      //these values are auto-escaped, so no worries on SQL injection
      if ($this-&gt;db-&gt;insert('redemption_information', $_POST)) {
          $data['message'] = "Your order has been taken, thanks for your interest!";
          $this-&gt;load-&gt;view('success_view', $data);
      }
      else {
          $data['message'] = "There was an error with your order. Please try again.";
          $this-&gt;load-&gt;view('submission_form_view', $data);
      }
      }
      }
  </code></pre>