title: Can a property of a PHP object be an array? And if so how do I add to it from within the object?
body: <p>I have an object to represent the combination of data from three tables, I'm trying to make this object as universal as possible so changes in the DB structure don't have to be reflected in the object and allowing the object to edit the 3 tables separately instead of making long complicated SQL join statements.</p>
  <p>Since the object represents a database table, public properties are needed/acceptable and I'm trying to generate them dynamically in the constructor but keeping the properties separate for the different database tables the information belongs in. (So that when I go to update one table, the information that has to be checked for changes and then sent to update is not mixed with the properties from the other tables)</p>
  <p>My first idea was to keep each table in an array inside the object properties for each table... But several attempts at adding data to the arrays comes out blank so it's either not possible and I've just snuck past errors with syntax that somehow makes sense or I'm doing it wrong.</p>
  <p>Any help?</p>
  <pre><code>class MemberObject
  {
    private $dbc;
    private $memberID;
    private $membersTable;
    private $affiliatesTable;
    private $clientsTable;
  
  // Each DB held in own array
    public $member = array();
    public $affiliate = array();
    public $client = array();
  
    public function __construct(PDO $dbc, $memberID)
    {
      $this-&gt;dbc = $dbc;
      $this-&gt;memberID = $memberID;
      $this-&gt;membersTable = new DatabaseTable($dbc, 'member', 'memberID');
      $this-&gt;affiliatesTable = new DatabaseTable($dbc, 'memberAffiliated', 'memberID');
      $this-&gt;clientsTable = new DatabaseTable($dbc, 'memberClient', 'memberID');
      $thisMember = $this-&gt;membersTable-&gt;findById($this-&gt;memberID);
      $this-&gt;populateData($thisMember, $this-&gt;member);
  
      if ($thisMember = $this-&gt;affiliatesTable-&gt;findById($this-&gt;memberID))
      { // IF get member from affiliatesTable
        $this-&gt;populateData($thisMember, $this-&gt;affiliate);
      }
  
      if ($thisMember = $this-&gt;clientsTable-&gt;findById($this-&gt;memberID))
      { // IF get member from clientsTable
        $this-&gt;populateData($thisMember, $this-&gt;client);
      }
    }
  
    private function populateData($dataArray, $targetTable)
    {
      foreach ($dataArray as $key =&gt; $value)
      {
        $targetTable[$key] = $value;
      }
    }
  
    public function saveEdit()
    {
      $membersTable-&gt;save($this-&gt;member);
      if (isset($this-&gt;affiliate['affiliateID']))
      {
        $affiliatesTable-&gt;save($this-&gt;member);
      }
      if (isset($this-&gt;client['clientID']))
      {
        $clientsTable-&gt;save($this-&gt;member);
      }
    }
  }```
  </code></pre>