Re: Extending PEAR::DB (static constructor issue?)
| From: | Paul Scott | Date: | Fri, 10 Mar 2006 04:31:16 +0000 |
| Subject: | Re: Extending PEAR::DB (static constructor issue?) | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23256@lists.php.net to get a copy of this message | ||
On Thu, 2006-03-09 at 20:06 -0800, Justin Patrin wrote:
> There is absolutely no way in PHP to know what class a statuc method
> is being called on (well, beside using debug_backtrace(), which would
> be a horrible solution), so DB does the normal thing and returns a
> normal DB object.
>
Another way of getting around this quite elegantly is to use an adaptor
pattern. Something like this:
require_once 'DB.php';
class myDB {
var $mydb;
function myDB($dsn)
{
$this->mydb = &DB::connect($dsn);
}
}
which will make a copy of the DB object in a property that can be used
in your class(es).
--Paul