RE: Re: Question about constructors and destructors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> For all to know
> This bug is linux AND windows, the problem is caused when you have the
> zend.ze1_compatibility_mode = On
> in the php.ini file. This is a bug that was reported before several 
> times without having been resolved. I commented and reactiveated the bug 
> on the php bug submission engine...

That actually makes total sense and might not be a bug.

Okay, I know, it's weird behavior, but:

> $mytest = new test();

Has different behavior in PHP4 than in PHP5.

In PHP4, the test() object is created; Then, because = is used, a copy of
that object is assigned to $mytest. The original copy of the object is then
destroyed at that point. This is why, in PHP4, you often see

> $mytest =& new test();

Which assigns by reference. Since PHP4 compatibility was enabled, there were
two copies of the object, and when the original copy went out of scope the
destructor was called.

PHP5 has a totally different way of handling this; If I understand
correctly, it works similarly to Java, in that you pass around handles to
the object instead of the object itself. So,

> $mytest = new test();

In PHP5 only creates one copy of the object, and $mytest is a handle to that
object.

This can be very confusing behavior, and I wish that it was more explicit in
the manual...

-K. Bear

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux