Re: why =&?

From: Date: Tue, 28 Jun 2005 20:09:25 +0000
Subject: Re: why =&?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19811@lists.php.net to get a copy of this message
* Martín Marqués <martin@bugs.unl.edu.ar>: > I just saw these lines in the PEAR::DB docs, and was wondering why "&" after > the equal sign? > > // Once you have a valid DB object named $db... > $res =& $db->query('DELETE * FROM clients'); In PHP4, in order to pass objects around, it's best to assign them by reference; otherwise you end up passing around copies of objects -- which is typically not the intention, and can often lead to errors. The query() method in DB returns a DB_Result or a DB_Error, both of which are objects. Thus the need for the above notation. This notation is not necessary in PHP5, but still recommended by many PHP-OOP advocates for backwards compatability, and to ensure that the original reference gets destroyed when creating a new object. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.pear.general (#19811) next »