title: How can I can get a child class's properties into the parent class's methods
body: <p>I have two classes: The first class - Database - handles all the database actions, i.e., insert, update, delete. The other handles class specific actions for the user. The user class extends the database class. The User class has all of the properties in it and am trying to get the methods from the Database class to perform actions on the properties from the User class. So I'm instantiating User in test.php:</p>
  <pre><code>&lt;?php 
  require_once(&quot;user.php&quot;);
  $user = new User();
  
  $user-&gt;auth(&quot;Scott&quot;, &quot;rascal&quot;);
  echo $user-&gt;username;
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>and I'm getting these errors:</p>
  <pre><code>Notice: Undefined property: Database::$dbFields in /Users/scottmcpherson/Sites/phpsites/projectx/application/models/db.php on line 24
  
  Warning: Invalid argument supplied for foreach() in /Users/scottmcpherson/Sites/phpsites/projectx/application/models/db.php on line 24
  
  Notice: Undefined property: Database::$tableName in /Users/scottmcpherson/Sites/phpsites/projectx/application/models/db.php on line 83
  
  Notice: Undefined property: Database::$id in /Users/scottmcpherson/Sites/phpsites/projectx/application/models/db.php on line 85
  
  Notice: Undefined property: Database::$dbFields in /Users/scottmcpherson/Sites/phpsites/projectx/application/models/db.php on line 24
  
  Warning: Invalid argument supplied for foreach() in /Users/scottmcpherson/Sites/phpsites/projectx/application/models/db.php on line 24
  </code></pre>
  <p>Here's the user class:</p>
  <pre><code>&lt;?php
  require_once(&quot;db.php&quot;);
  
  class User extends Database{
  
      public $dbFields = array('username', 'password');
  
      public $tableName = &quot;users&quot;;
      public $id;
      public $username;
      public $password;
  
      public function auth($user, $pass){
          $this-&gt;username = $user;
          $this-&gt;password = $pass;
      
      }
  }
  ?&gt;
  </code></pre>
  <p>And here's the section of the database class that's giving me trouble:</p>
  <pre><code>&lt;?php 
  require_once(&quot;../config/main.php&quot;);
  
  class Database{
  
  
   public $db;
  
  public function __construct() {
      $this-&gt;connect();
  }
  
  public function connect(){
  try {
      $this-&gt;db = new PDO(&quot;mysql:host=&quot;.DB_SERVER.&quot;; dbname=&quot;.DB_NAME, DB_USER, DB_PASS);
      $this-&gt;db-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
      } catch (PDOException $e) {
      echo 'Connection failed: ' . $e-&gt;getMessage();
      }
  }
  
  public function properties() {
      $properties = array();
      foreach ($this-&gt;dbFields as $field) {
          if (isset($this-&gt;field) || property_exists($this, $field)) {
              $properties[$field] = $this-&gt;$field;            
          }
      }
      return $properties;
  }
  </code></pre>
  <p>I had everything working fine until I tried to extend the class and move the properties to the child class. How do I get past the errors and achieve this correctly?</p>