When do you use an instance of a class ($db = new database();$db->query($sql)) and when do you immediately use the class itself (database::query($sql)) ?
Are there "best practices" ?
I always used instances ($db = new ...) but saw in the code of patTemplate et.al (www.php-tools.de) that they linked directly to the class, thus preventing all problems related to where to define the database connection etc...
class person {
function new() {
db::query($sql);
}
}
instead of
class person {
function person {
$this->db = new database();
}
function new() {
$this->db->query($sql);
}
}
What do you do ? When do you use what?