title: PHP Use child variable to create a class in parent class
body: <p>I have 3 classes:</p>
  
  <ol>
  <li>Class A - Parent Class</li>
  <li>Class B - Child Class</li>
  <li>Class C - Class to be used in Class A</li>
  </ol>
  
  <p>I want to use functions from class C using variables from my Child class.</p>
  
  <pre><code>&lt;?php
  
  class A
  {
      public function __construct()
      {
          $this-&gt;load();
      }
  
      public function load()
      {
          $class = new C();
          $class-&gt;test = $this-&gt;test;
          $this-&gt;c = $class;
      }
  }
  
  class B extends A
  {
  
      public function __construct()
      {
          parent::__construct();
      }
  }
  
  class C
  {
      public function display()
      {
          echo $this-&gt;test;
      }
  }
  
  $b = new B();
  $b-&gt;test = 1;
  $b-&gt;c-&gt;display();
  </code></pre>