I often use static "factory" methods to create objects from database.
class Job {
protected $objDb;
public function __construct($objDb) {
$this->objDb = $objDb;
}
public static function LoadArrayByProjectId($intProjectId, $objDd) {
//some code that loads the jobs
$objJob = new Job($objDb);
$arr[] = $objJob;
//end of loop
return $arr;
}
public static function LoadArrayByUserId($intUserId, $objDb) {
//similar code
}
}
So I try to use Dependency Injection by passing into the constructor the $objDb. The problem is the $objDb param in the static functions. It's very annoying to pass the param around.
How do you handle this case? Are there better solutions?