title: “Unexpected T_OBJECT_OPERATOR” error in PHP
body: <p>I am getting the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Parse error: syntax error, unexpected T_OBJECT_OPERATOR in.. on line 52.
  </code></pre>
  
  <p>Line 52 is <code>if ($result = mysqli-&gt;query...</code>. If I comment out the line, the same error occurs on <code>$mysqli-&gt;query("INSERT INTO...</code>.</p>
  
  <p>Why does this give the error?</p>
  
  <pre><code>$unique_code = "";
  $inserted = false;
  while(!$inserted) {
      $unique_code = generateCode();
      echo $unique_code;
  
      // Check if it exists
      if ($result = mysqli-&gt;query("SELECT unique_code FROM coming_soon_emails WHERE unique_code = '$unique_code'")) {
          // Check no record exists
          if ($result-&gt;num_rows == 0) {
              // Create new record
              $mysqli-&gt;query("INSERT INTO coming_soon_emails (email,unique_code) VALUES ('" . $mysqli-&gt;real_escape_string($_POST['email']) . "','$unique_code')");
              // Set inserted to true to ext loop
              $inserted = true;
              // Close the result object
              $result-&gt;close();
          }
      } else {
          // Quit if we can't check the database
          die('Something went wrong with select');
      }   
  }
  </code></pre>