Re: Re: error when using $this

From: Date: Fri, 22 Aug 2003 04:59:24 +0000
Subject: Re: Re: error when using $this
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-160390@lists.php.net to get a copy of this message
Jonathan Villa wrote: > 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'm guessing this is your class constructor? If so then you can't access $this->_dbuser and $this->_dbpw because you have not set their value anywhere. You cannot set their value in the section you labeled "var declarations" either. PHP does not allow values to be assigned to variables outside of functions. So if you have any assignments in the var declaration section put those at the top of your constructor. Jean-Christian Imbeault

« previous php.general (#160390) next »