Found the problem...

From: Date: Thu, 26 Jul 2007 21:15:08 +0000
Subject: Found the problem...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259597@lists.php.net to get a copy of this message
Found the problem. The piece of code was outside of a block where $db had been created, so it was a non-object the whole time... Easily fixed, but a hard error to find when I'm assuming it's my brand new class that's the problem. -- Rob ""Rob Adams"" <rob_adams@hotmail.com> wrote in message news:91.27.10081.BDB09A64@pb1.pair.com...
I need to test a bunch of code that extensively uses a mysql database (both selects and inserts), and I want to do it without actually writing to the database.. Instead of commenting out all of the $db->query($insert_query) statements and echoing $insert_query, I thought I'd make the following object: class TestDB { var $realDB; function TestDB(&$o) {
       echo $o;
       $this->realDB = &$o;
       echo $this->realDB;
} function query($q) {
       echo $q;
} function getOne($q) {
       return $this->realDB->getOne($q);
} function getRow($q) {
       return $this->realDB->getRow($q);
} function &resetDB() {
       return $this->realDB;
} } Then, in my code, I instantiate it like so:
           $tmp = new TestDB($db);
           $db = &$tmp;
But this doesn't work, and I can't figure out why. When I try to call $db->getRow($q) I was getting an error that said that I couldn't call a member function of a non-object. I've changed things around now, and I'm just not getting anything. Any idea why I would get the non-object error? Thanks.


« previous php.general (#259597) next »