Re: referencing a class

From: Date: Wed, 08 Sep 2004 13:34:04 +0000
Subject: Re: referencing a class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196117@lists.php.net to get a copy of this message
* Jed R. Brubaker <jrb21398@hotmail.com>: > Quick question here. Has anyone run into trouble with a variable reference > to a class object? > > Here is the code: > $_SESSION['database'] = new Database; > $this->db = &$_SESSION['database']; > > Everything goes screwy after a call like this. You don't say what version of PHP you're using, but I'm guessing 4 (as PHP5 passes all objects by reference). They way I've handled the above is as follows: $_SESSION['database'] =& new Database; $this->db =& $_SESSION['database']; You need to get a reference to the object from the very beginning; I've tried a variety of ways, and this is the only one that works consistently. -- Matthew Weier O'Phinney | mailto:matthew@garden.org Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org

« previous php.general (#196117) next »