Is it a bad idea for a model class hold the db handler as a property? Example code are as below. I think the second is better, but the first is not so bad in my opinion.
First:
class ActiveModel {
protected $db;
public function __construct() {
$this->db = DbFactory::get('Foo');
}
public function save() {
//use $this->db to do the job;
....
}
}
Second:
class ActiveModel {
public function save($db = null) {
if ($db === null) {
$db = DbFactory::get('Foo');
}
//then use $db to do the job;
....
}
}