Okay, I understand more now ...

I played with this for a couple of minutes and can see exactly where is acting odd, which is exactly where you indicated. :) I tried a couple of things to keep the instance of the object, but the variable keeps getting set back.

One thing I did that worked was to create a variable in the factory object class and store a reference of the foo instance in that variable.

ex:
$g_fooInstance =& new foo();
$this->fooInstance =& $g_fooInstance;

I tried giving the variable values prior to it being overwritten with the reference pointer, and always my values prior were magically recreated after the object was instanciated.

Rasmus, any ideas here? I'm thinking this is a bug.

--
Jason k Larson


Jens von Pilgrim wrote:
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




-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to