title: "Cannot access protected property" Error
body: <p>I have two classes involving composition not inheritance., class A and class B. One of class A's properties is an array of class B objects. Class A has a public method <code>A::getName()</code>. Class B also has a public method with the same name. The method for class A is as follows:</p>
  
  <pre><code>public function getName()
  {
      return $this-&gt;_name;
  }
  </code></pre>
  
  <p>My problem is when I'm in Class B and I try to access this public method for class A, I get the "cannot access protected property" error. <code>$_name</code> is a private property in each class. Class A's would be the name, for example, of a form, and for B, the name of the field.</p>
  
  <p>This is the code that generates the error (constructor for class B):</p>
  
  <pre><code>public function __construct($name)
  {
      $this-&gt;foo = A::getName() .'-'. $name;
  }
  </code></pre>
  
  <p>Why is it not allowing me to access class A's public method getName()? Any way to fix or get around this?</p>
  
  <hr>
  
  <p>FIX:</p>
  
  <p>I realized I was invoking class A's method statically, though I need to deal with each object individually, as each object has a unique name. To solve my issue I gave a public set function for class B for the unique name, and called that in class A:</p>
  
  <pre><code>class A
  {
      ...
  
      $this-&gt;list[$B_name] = new B($B_name);
  
      $this-&gt;list[$B_name]-&gt;setID($this-&gt;_name, $B_name);
  
  }
  
  class B
  {
      ...
  
      public function setID($name, $subName)
      {
          $this-&gt;foo = $name .'-'. $subName;
  }
  </code></pre>