People say Service Locators are bad because they expose the dependencies in some random method from the class (and not in the constructor's arguments like it should):
class A{
function F(){
DB::query(...)
}
}
instead of
class A{
protected $db;
function __construct(DB $db){
$this->db = $db;
}
function F(){
$this->db->query(...);
}
}
But consider a function, like imagejpeg() from GD. Obviously you can't "inject" that, so you have to call it somewhere in your class, just like your service. So isn't this the same thing? That function is a dependency too.
Or what about instantiating an object somehwere in your class methods, like PDO. Aren't these things exactly like services after all? So why all the fuss about service locators being evil?
Not constructive - This question is not a good fit to our Q&A format. We expect answers to generally involve facts, references, or specific expertise; this question will likely solicit opinion, debate, arguments, polling, or extended discussion.. The question is asked with a lot of bias. She's making the assumption that service locators are bad. It's clear where she stands on the issue, and that's not what we're looking for in questions. – jmort253 Mar 3 '12 at 19:01