title: PHP classes and static variables - Should I use __destruct()?
body: <p>I have a class that's similar to the following:</p>
  
  <pre><code>class Person
  {
      private static $_sqlData;
  
      public function __construct($id)
      {
          if (!self::$_sqlData)
          {
          self::$_sqlData = // GET THE DB STUFF
          }
      }
  
      public function getName()
      {
          return self::$_sqlData['name'];
      }
  }
  </code></pre>
  
  <p>This has been working fine until I needed to place it in a loop.</p>
  
  <pre><code>foreach ($ids as $id)
  {
      $person = new Person($id);
      echo $person-&gt;getName();
  }
  </code></pre>
  
  <p>This continues to return the first persons name rather than all the names for the given IDs. The reason being the static variable.
  I've overcome this by adding in a <code>__destruct()</code> function to set <code>$_sqlData</code> to false then calling <code>unset()</code> on <code>$person</code> in the <code>foreach()</code> loop.</p>
  
  <p>Is this a good way of handling this? Should I be approaching this differently?</p>