title: What's the best way to store PHP class properties?
body: <blockquote>
    <p><strong>Duplicate of:</strong> <a href="https://stackoverflow.com/questions/546403/whats-the-best-way-to-store-class-variables-in-php">What&#39;s the best way to store class variables in PHP?</a></p>
  </blockquote>
  
  <p>For some time I've been having this discussion with a co-worker on how should you store attributes within a PHP class.</p>
  
  <p>So which one do you think it should be used. Something like this: </p>
  
  <pre><code>Class test{
      public $attr1;
      public $attr2;
      .............. 
      public function __construct(){
          $this-&gt;attr1 = val;  
          $this-&gt;attr1 = val;
          ...................   
      }
  }
  </code></pre>
  
  <p>Versus:</p>
  
  <pre><code>Class test{
      public $data;
  
      public function __construct(){
          $this-&gt;data['attr1'] = val;
          $this-&gt;data['attr2'] = val;
          ..........................       
      }
  }
  </code></pre>
  
  <p>This is important when you have objects with many attributes that have to be stored and retrieved within often.</p>
  
  <p>Also important when dealing with objects with many attributes, do you use getters and setters for each attribute or rather one method to set all and one method to get all ?</p>