While creating classes, I followed OO conventions and declared all class variables before using them:
class myClass { private $property1, $property2, ...; public __constructor() { $this->property1 = $this->property2 = NULL; } } But I realized that PHP is scripting language and not following OO concepts strictly, so we can 'generate' class property dynamically:
class myClass { public __constructor() { $this->fields = $this->db->getFields(TABLE_NAME); foreach($this->fields as $fld) { $this->{$fld} = NULL; } } } 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 ?