title: Am I using OOP correctly?
body: <p>I've been developing a PBBG (game) written in PHP &amp; MySQL for 7 months. The project is almost done and might be released soon, but I am worried about some issues.</p>
  <p>This was my first time programming a real project, and also my first time using OOP. My code now has about 25k lines, and here is my question:</p>
  <p>Am I using OOP correctly? I believe I'm calling classes constructs excessively. I have about 20 different classes, and sometimes they need each other. Here is a sample code how I use OOP: (Just a sketch, might not work)</p>
  <pre><code>class A {
      
      public $b;
      public $c;
  
      public function __construct(){
          $b = new B();
          $c = new C();
      }
  
      public function sampleA(){
          //some stuff that depends $c-&gt;sampleC
      }
  
  }
  
  class B { 
  
      public $c;
  
      public function __construct(){
          $c = new C();
      }
  
      public function sampleB($id){
          return $this-&gt;c-&gt;sampleC($id);
      }
  
  }
  
  class C {
  
      public function sampleC(){
  
      }
  
  }
  </code></pre>
  <p>Then I'd use:</p>
  <pre><code>$a = new A();
  $b = new B();
  $c = new C();
  
  $whatIWant = $a-&gt;sampleA($b-&gt;sampleB($c-&gt;sampleC()));
  </code></pre>
  <p>While I could just</p>
  <pre><code>$a = new A();
  $whatIWant = $a-&gt;sampleA($a-&gt;b-&gt;sampleB($a-&gt;c-&gt;sampleC()));
  </code></pre>
  <p>This looks uncalled-for on this simple example, but I'm having on my script more than 200 different constructor calls, I guess this will slow down and overload my server.</p>
  <p>Maybe my example wasnt very clear, so I took a print of my xdebug profiler result:</p>
  <p><a href="https://i.stack.imgur.com/rLWjl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rLWjl.jpg" alt="Print" /></a></p>
  
  <p>Is singleton what I need? I tried using a simple example like this with singleton, but I had the same result (more than 1 construct per class).<br/>
  Maybe I need to extend these classes and use parent's constructor? But how will it be possible with 20 different classes, sometimes independent, and sometimes dependent of each other?<br/>
  Or maybe I am using it the correct way (what I dont think so)</p>