OO PHP question regarding arrays
<p>I'm trying to learn object oriented PHP by porting some of the simple exercises I've learnt in Java to PHP. This is one of them, to calculate the total salary of 3 people. </p>

<p>I'm apparently having a problem with the array in the family class - php gives an error about "Undefined variable: a_family" on line 32. Could anybody point me in the correct direction?</p>

<pre><code>&lt;?php
    class person {
     private $name;
     private $salary;

     //constructor
     function __construct($given_name, $given_salary) {
      $this-&gt;name = $given_name;
      $this-&gt;salary = $given_salary;
     }

     //getter for salary
     function get_salary() {
      return $this-&gt;salary;
     }

    }

    class family {
     private $a_family;

     function __construct() {
      $a_family = array();
     }

     function add_family_member($given_person) {
      $a_family[] = $given_person;
     }

     function get_total_salary() {
      $total_salary = 0;
      foreach ($a_family as $member) {
       $total_salary = $total_salary + $member-&gt;get_salary();
      }

      return $total_salary;
     }
    }

    $mum = new person("Mummy", 500);
    $dad = new person("Daddy", 1500);
    $sis = new person("Sister", 20);

    $my_family = new family();

    $my_family-&gt;add_family_member($mum);
    $my_family-&gt;add_family_member($dad);
    $my_family-&gt;add_family_member($sis);

    $family_income = $my_family-&gt;get_total_salary();

?&gt;

&lt;!-- start HTML --&gt;
&lt;html&gt;
    &lt;head&gt;

    &lt;/head&gt;

    &lt;body&gt;
     &lt;p&gt;My total family income is $&lt;?php echo $family_income; ?&gt;.&lt;/p&gt;
    &lt;/body&gt;

&lt;/html&gt;
</code></pre>
