RE: [PHP] Problem with "=& new" and locally created instances

From: Date: Fri, 28 Mar 2003 12:49:30 +0000
Subject: RE: [PHP] Problem with "=& new" and locally created instances
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-141430@lists.php.net to get a copy of this message
Hello, Jason wrote: JL> Maybe I'm missing something here ... but what is the point of trying JL> to create a reference to a new object ... it hasn't been ceated prior JL> to make reference to. Can't you simply create the new object and JL> then make whatever (if needed) references? Uhh... maybe I'm missing someting, too? We're talking about he followin line, don't we? $g_fooInstance =& new foo(); // <-- here's the problem IMHO this line causes no problem... using the & operator with new is explicitly noticed in the php manual (Chapter 15): "The same syntax can be used with functions, that return references, and with new operator (in PHP 4.0.4 and later): $bar =& new fooclass();" The problem is, that the object created in that line is destructed when the function is left. Or, in other words, an object is destructed automatically by the php-engine, although a) the object is still referenced and b) even no local variable has ever referenced it. BTW: Of course the code here doesn't make really sense (according to your last sentence), but it's only an example for illustrating the problem. Regards, Jens

« previous php.general (#141430) next »