title: Is it good idea to create dynamic class variables in PHP?
body: <p>While creating classes, I followed OO conventions and declared all class variables before using them:</p>
  
  <pre><code>    class myClass {
        private $property1, $property2, ...;
  
        public __constructor() {
           $this-&gt;property1 = $this-&gt;property2 = NULL;
        }
  
      }
  </code></pre>
  
  <p>But I realized that PHP is scripting language and not following OO concepts strictly, so we can 'generate' class property dynamically:</p>
  
  <pre><code>    class myClass {
        public __constructor() {
           $this-&gt;fields = $this-&gt;db-&gt;getFields(TABLE_NAME);
  
           foreach($this-&gt;fields as $fld) {
             $this-&gt;{$fld} = NULL;
           }
        }
  
      }
  </code></pre>
  
  <p>Is this a good approach ?
  I think dynamically generated properties would have public access by default, so that could be one disadvantage and such automation could be one advantage.
  Is there any difference in terms of performance ?</p>