Re: Re: error when using $this

From: Date: Fri, 22 Aug 2003 00:22:57 +0000
Subject: Re: Re: error when using $this
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-160372@lists.php.net to get a copy of this message
I am in a class as well as a constructor. class DBI { //var declarations function DBI() { $retVal = true; $this->setDBConn(mysql_connect('localhost',$this->_dbuser,$this->_dbpwd)); if ($this->getDBConn() == false) $retVal = false; if(mysql_select_db($this->getDBName(),$this->getDBConn())==false) $retVal = false; return $retVal; } //more functions... } I even tried removing $this->_dbuser and $this->_dbpwd and replacing them with hardcoded data, and the error persists. On Thu, 2003-08-21 at 19:19, DvDmanDT wrote: > Has with classes to do... The error claims that code isn't in a class which > makes it invalid as $this is the current class... If you aren't in a class > then there's no $this... however, if you are in a class, you just found a > bug or a typo in your script... > > -- > // DvDmanDT > MSN: dvdmandt@hotmail.com > Mail: dvdmandt@telia.com > "Jonathan Villa" <jvilla@isdesigndev.com> skrev i meddelandet > news:1061510870.3585.2.camel@in-hoc-vince... > > First of all, let me say that I am using PHP 5, but not including any > > new php5 features, just installed it. > > > > Anyway, > > > > this is the offending code.. > > > > $retVal = true; > > > > $this->setDBConn(mysql_connect('localhost',$this->_dbuser,$this->_dbpwd)); > > if ($this->getDBConn() == false) > > $retVal = false; > > > > and on my page I get the following error: > > > > Fatal error: Using $this when not in object context in /var/www/xxxxx > > > > Now this is code I've used time and time before...also, I have never > > seen an error such as the above. > > > > Any ideas? > > > >

« previous php.general (#160372) next »