My abstract class Database is made for database interaction and any child of this class (UserDatabase, ActionDatabase, EventDatabase) inherits its database connection which is defined as static.
abstract class Database {
public static $connection;
public function __construct( ) {
...
$this->connection = mysql_connect( $host, $username, $password );
}
}
class UserDatabase extends Database {
public function verify( ) {
if ( $this->connection == parent::$connection ) {
print "true";
} else {
print "false";
print "this:" . $this->connection . " parent:" . parent::$connection;
}
}
}
$instance = new UserDatabase( );
$instance->verify( );
// this prints false, as parent::$connection is empty
Does that mean, that my database connection is only set up and stored in memory once and passed on to subclasses as reference without being replicated for each instance?
Is this how you would implement you OOP-correct database interface?