$db = &DB::connect($dsn, $properties);
Why it is impossible to write just like this:
$db = new DB(); $db->connect($dsn,$properties); .... .... //receive an orgasm
?
$db = &DB::connect($dsn, $properties);
Why it is impossible to write just like this:
$db = new DB(); $db->connect($dsn,$properties); .... .... //receive an orgasm
?
A friendly site discussed the topic: Constructors vs Factory Methods .
UPD:
Static factory methods vs. constructors + translation
The articles are about Java, but in principle these theses are applicable to PHP. In this situation, for example, the connect method can return an already existing database connection object - and it will not be necessary to connect in a new way. Or it can return different types of objects. For example, Zend_Db, depending on the transferred configuration, returns objects of a particular class (depending on the type of database)
Source: https://ru.stackoverflow.com/questions/103062/
All Articles