Re: RE : [PHP] Weird problem with objects

From: Date: Fri, 23 Jan 2004 11:14:07 +0000
Subject: Re: RE : [PHP] Weird problem with objects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-175502@lists.php.net to get a copy of this message
Vincent DUPONT wrote:
what do you mean by this :Additionally, you might want to assign the reference of the new objects otherwise PHP will create a new object and then make a copy of it - not very efficient. Like so... $this->database = & new database(); $this->accessory = & new accessory(); $this->order = & new order();
The = operator makes a copy of the right side and puts it into the left side. So the "new database()" bit will create a new object of type database. The = operator will then make a copy of that object and put it into $this->database. So it's actually creating 2 database objects one of which will get deleted at the end of the function. By assigning the reference (that's what the & gets) only one object is created. Does that make sense now? -- Stuart

« previous php.general (#175502) next »