Duplicate of: http://stackoverflow.com/questions/546403/whats-the-best-way-to-store-class-variables-in-php
For some time I've been having this discussion with a co-worker on how should you store attributes within a PHP class.
So which one do you think it should be used. Something like this:
Class test{
public $attr1;
public $attr2;
..............
public function __construct(){
$this->attr1 = val;
$this->attr1 = val;
...................
}
}
Versus:
Class test{
public $data;
public function __construct(){
$this->data['attr1'] = val;
$this->data['attr2'] = val;
..........................
}
}
This is important when you have objects with many attributes that have to be stored and retrieved within often.
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 ?