title: This echo inside an if/else block is not working at the end of a script
body: <p>I've looked at similar questions posted here as well as did a basic Google search but the best I could find is about why W3Schools is a horrible place to learn from which didn't help much with my problem. I don't necessarily want a solution, I'd prefer an explanation as to why this isn't working as I have had a similar problem in the past but worked around since this is me simply debugging and testing other sections of code.</p>
  
  <p>To begin with, I've got a pesky echo inside an if statement that isn't printing, the funny thing is that neither the if, nor the else block appear to be executed.</p>
  
  <p>My <code>index.php</code> file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;A Title&lt;/title&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;?php
              session_start();
  
              include "scripts/Employee.php";
  
              error_reporting(E_ALL);
  
              $user = new Employee('bbuck', 'password');
  
              echo "&lt;p&gt;I have some stuff that works here.&lt;/p&gt;";
  
              if (!($user-&gt;error() === false)) {
                  echo "&lt;p&gt;Authenticated!&lt;/p&gt;";
              }
              else {
                  echo $user-&gt;error();
              }
          ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The <code>Employee</code> constructor:</p>
  
  <pre><code>public function __construct($username, $password) {
      $db = Database::getInstance();
  
      $result = $db-&gt;authenticate($username, $password);
      if ($result !== false) {
          $this-&gt;id = $result['id'];
          $this-&gt;fname = $result['fname'];
          $this-&gt;lname = $result['lname'];
          $this-&gt;lastAction = $result['last_action'];
          $this-&gt;error = false;
      }
      else
          $this-&gt;error = "Failed to authenticate the user, wrong username/password combination.";
  }
  </code></pre>
  
  <p>I don't think it's really important, but just as a reference the <code>Employee::error()</code> function is simply <code>return $this-&gt;error;</code>.</p>
  
  <p>And finally, the <code>Database::authenticate()</code> function:</p>
  
  <pre><code>public function authenticate($username, $password) {
      $query = "SELECT * FROM `employee` WHERE `username` = '" 
          . $this-&gt;conn-&gt;escape_string($username) 
          . "' AND `password` = PASSWORD('"
          . $this-&gt;conn-&gt;escape_string($password) . "')";
  
      $result = $this-&gt;conn-&gt;query($query);
  
      if (!$result)
          return false;
  
      $rowCount = $result-&gt;num_rows;
  
      if ($rowCount == 1) {
          $row = $result-&gt;fetch_assoc();
          $update = "UPDATE `employee` SET `session_id` = UUID(), `session_expires` = (NOW() + INTERVAL 10 MINUTE) WHERE `id` = {$row['id']}";
          $select = "SELECT `session_id`, `session_expires` FROM `employee` WHERE `id` = {$row['id']}";
  
          $updateResult = $this-&gt;conn-&gt;query($update);
  
          if (!$updateResult)
              die("Failed to update the employee!");
  
          $updateResult = $this-&gt;conn-&gt;query($select);
  
          if (!$updateResult)
              die("Failed to pull Session data for employee!");
  
          $updateRow = $updateResult-&gt;fetch_assoc();
          $_SESSION[SESSION_ID] = $updateRow['session_id'];
          $_SESSION[SESSION_EXPIRES] = new DateTime($updateRow['session_expires']);
  
          return $row;
      }
  
      return false;
  }
  </code></pre>
  
  <p>Now, the echo statements within the <code>if/else</code> block of <code>index.php</code> are not printing anything, I've used <code>var_dump</code> on <code>$user</code> and <code>$user-&gt;error() === false</code> and both gave me the results that I expected to receive from them. I've also placed an <code>echo</code> before the if statement and it worked, as well as one after the statement, it also worked. I'm confused as to why they are being overlooked.</p>
  
  <p>This is for debugging, I'm trying to test code, but as I said, I'm curious why this is being skipped because I've encountered this before.</p>