title: PHP OOP, undefined property. How can I get this to work?
body: <p>Okay so I'm basically trying to improve with PHP OOP, however I'm not too sure how I should do this. Could someone please point out the issue?</p>
  
  <p>The code returns the following errors:</p>
  
  <p>Notice: Undefined property: registration::$userExist
  Fatal error: Call to a member function fetch() on a non-object</p>
  
  <p>The class:</p>
  
  <pre><code>class registration extends connect{
  
          public function userExist(){
              global $dsn;
  
          $userExist = $this-&gt;dsn-&gt;prepare("
              SELECT * FROM accounts
              WHERE username= :username
              ");
  
  $userExist-&gt;bindParam(':username', $username);
              $userExist-&gt;execute();
  
          $rows = $this-&gt;userExist-&gt;fetch(PDO::FETCH_NUM);
              return $rows;
          }
  </code></pre>
  
  <p>How I'm trying to use the class on a page:</p>
  
  <pre><code>$conn = new connect();
  $registration  = new registration();
  
  $rows = $registration-&gt;userExist();
                      if($rows &lt; 1){
  // do something
  </code></pre>