Starting with version 5.3, PHP supports late binding for static methods. While it\'s an undoubtedly useful feature, there are only several cases where its use is really nece
static methods (early- or late-bound) create tight coupling and (thus) reduce testability. you can create large programs in PHP without using more than a few static calls. for me, late static methods are a non-feature.
edit to answer Marco Demaio's question, how do static method reduce testability?
i'm sorry if this is all obvious to you, static members (both data and methods) are useful and do no harm if used responsibly, i was alluding to their prevalent misuse.
say you have a web application that uses an SQL database. your business objects may retrieve data using a static interface or through polymorphism. either
class MyBusinessObject
extends...
{
public function doThisOrThat(...)
{
$results = db::query('sql string...');
...
}
}
or
class MyBusinessObject
extends...
{
public function __construct(dbconn $db)
{
$this->db = $db;
}
private $db;
public function doThisOrThat(...)
{
$results = $this->db->query('sql string...');
...
}
}
the latter is easier to test (as in: i want to test that the sql string constructed from such-and-such inputs is such-and-such) because it's easier to create another implementation of the dbconn interface than it is to change the meaning of db::. why you'd want either? because you don't need a real database to test the sql-composing behavior, and in fact it's easier to test for without a real database. also, it's easier to stub out the sql consumer if your tests are concerned with another aspect of the CUT (Code Under Test).
testing always implies lying to the tested code about its collaborators, and abstaining from static interfaces (the "doublecolon" or "quadridot") means the lie need not be a massive surgery, which is a plus, since the farther the tested code is from the production code, the less meaningful the test results are.