Testing for instance of pear DB.

From: Date: Tue, 16 Apr 2002 21:46:25 +0000
Subject: Testing for instance of pear DB.
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1148@lists.php.net to get a copy of this message
I have a script that passes an instance of pear DB to several different objects so they can use it internally to make queries. I'd like to set up my objects so that they test whether or not they have been passed an actual instance of pear's DB class and if not, then I want them to create one internally. class someObj { //properties var $DB; //constructor function someObj($passedResource) { if(test for whether or not the object is a pear DB resource) $this->DB = $passedResource; else $this->DB = DB::Connect($someDsn); } } The problem I have is how to test whether or not the passedResource is a pear DB object. If i use get_class() it returns "db_mysql". The problem with that is that if I start testing against "db_mysql" then the script is no longer database independant because if I switch databases, then the object will, I assume, be derived from a different class. So I need a solid way to test whether a variable is an instance of a pear DB connection object.

« previous php.pear.general (#1148) next »