What does the following syntax mean?

Why can’t you just write:

$db = new DB();
$db->connect($dsn,$properties);
....
....
//receive an orgasm

?


Answer 1, authority 100%

A friendly site discussed the topic: Constructors vs Factory Methods.

UPD:

Static factory methods vs. constructors+ translation

The articles talk about Java, but in principle these theses apply to PHP as well. In this situation, for example, the connect method can return an already existing database connection object – and there will be no need to connect again. Or it can return different types of objects. For example, Zend_Db, depending on the passed configuration, returns objects of one class or another (depending on the type of database)

Leave a reply

Please enter your comment!
Please enter your name here