title: Magic getter inheritance
body: <p>I’m following <a href="https://teamallegiance.com/resources/better-getters-and-setters-php/" rel="nofollow noreferrer">this article</a> to try to make each of my PHP classes, inherit from a getter defined in a base class. I would found this very convenient not to rewrite magic getters in each and every class… (maybe it has bad consequencies ? if so, please tell me !) The thing is I have this error : <code>Undefined property: Personne::$nom</code>, and I don’t know why.</p>
  <p>Here’s the code :</p>
  <pre><code>class classeBase {
      public function __get($propriete) {
          if(property_exists($this,$propriete)) return $this-&gt;$propriete; 
          else return null;
      }
  }
      
  class Personne extends classeBase {
      private $nom;
      private $prenom;
          
      //constructor...
  }
      
  $p1 = new Personne(array(&quot;nom&quot; =&gt; &quot;nom1&quot;, &quot;prenom&quot; =&gt; &quot;prenom1&quot;));  
  echo $p1-&gt;nom;
  echo $p1-&gt;prenom;
  </code></pre>
  <p>3 more precisions :</p>
  <ul>
  <li>The constructor works fine (a <code>var_dump()</code> of the created instance shows <code>nom1</code> and <code>prenom1</code> well assigned)</li>
  <li>I have the same error with the code of the article, when I try to get to each properties of an instance of <code>Example_Object</code></li>
  <li>I don’t have any error when the magic getter is defined inside the <code>Personne</code> class</li>
  </ul>
  <p>Can somebody explain me what’s going on here ? (maybe what I wan’t to do is impossible)</p>
  <p>Thanks !</p>