note 55423 modified in ref.classobj by jome
| From: | jome@php.net | Date: | Sun, 25 Sep 2005 11:39:44 +0000 |
| Subject: | note 55423 modified in ref.classobj by jome | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-95752@lists.php.net to get a copy of this message | ||
as for zabmilenko's solution:
wouldn't it be better to create it this way?
<?php
// The base class for all db classes
class DB {
protected $connectId;
}
// Class for MySQL, which extends base class
class MySQL extends DB {
function connect () {
$this->connectId = mysql_connect (...);
}
}
// Class for PostgreSQL, which extends base class
class pgSQL extends DB {
function connect () {
$this->connectId = pg_connect (...);
}
}
// and then call constructor like this:
$dbName = "MySQL";
$db = new $dbName ( ... );
// ... which creates an object of class MySQL
?>
--was--
as for zabmilenko's solution:
wouldn't it be better to create it this way?
<?php
// The base class for all db classes
class DB {
protected $connectId;
}
// Class for MySQL, which extends base class
class MySQL extends DB {
function connect () {
$this->connectId = mysql_connect (...);
}
}
// Class for PostgreSQL, which extends base class
class pgSQL extends DB {
function connect () {
$this->connectId = pg_connect (...);
}
}
// and then call constructor like this:
$dbName = "MySQL";
$db = new $$dbName ( ... );
// ... which creates an object of class MySQL
?>
http://php.net/manual/en/ref.classobj.php