title: Which method is more efficient in constructing classes?
body: <p>For each of a bunch of records from my database I instantiate a class. Inside that class I call another class.</p>
  
  <h3>Example</h3>
  
  <pre><code>$records = array(...);
  foreach ($records as $record) {
      $a = new A();
      $data = $a-&gt;doSomething($record);
  }
  
  class A {
      protected $b;
      public function __construct()
      {
          $this-&gt;b = new B();
      }
  
      public function doSomething($param)
      {
          return $this-&gt;b-&gt;doSomething($param);
      }
  }
  </code></pre>
  
  <p>The above code is the way I'm currently doing it. However I was wondering if the below would be better:</p>
  
  <pre><code>$records = array(...);
  $b = new B();
  foreach ($records as $record) {
      $a = new A($b);
      $data = $a-&gt;doSomething($record);
  }
  
  class A {
      protected $b;
      public function __construct($b)
      {
          $this-&gt;b = $b;
      }
  
      public function doSomething($param)
      {
          return $this-&gt;b-&gt;doSomething($param);
      }
  }
  </code></pre>
  
  <p>What I would like to know, is if this is efficient at all, which of those options is better and if there are any other solutions that are even better.</p>