RE: [PHP] Re: Question about constructors and destructors

2006-06-28 Thread KermodeBear
 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



Re: [PHP] Re: Question about constructors and destructors

2006-06-28 Thread Jochem Maas
I tested on linux also and found no problem ...

Mathieu Dumoulin wrote:
 For all to know
 
 This bug is linux AND windows, the problem is caused when you have the
 
 zend.ze1_compatibility_mode = On

now it makes sense ... someone else offered a pretty good explanation
as to why you see the 'buggy' behaviour.

I'll go out on a limb and say that the 'bug' will likely never be fixed,
assuming it even should be (the behaviour seems to me to be consistent
with php4 OO functionality - namely passing objects by value)

zend.ze1_compatibility_mode is next to useless in practice for anything
but the most simple php4 OO code. certainly if you are wanting to
use php5 specific OO functionality like __destruct() you should not be using
ze1_compatibility_mode.

 
 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...
 
 Thanks all for your support
 
 Math
 
 Mathieu Dumoulin wrote:
 I posted a bit earlier and did some other tests and now i have a VERY
 simple question... check the following code :

 ===

 class test {
 public function __construct(){
 echo 'Buildingbr';
 }
 public function __destruct(){
 echo 'Destroyingbr';
 }
 }

 echo 'Will buildbr';
 $mytest = new test();
 echo 'Finished buildingbr';

 echo 'Unsetingbr';
 unset($mytest);
 echo 'Unset completebr';

 ===

 Althought you may think this will give the following output:

 Will build
 Building
 Finished building
 Unseting
 Destroying
 Unset complete

 Instead it outputs the following:

 Will build
 Building
 Destroying
 Finished building
 Unseting
 Destroying
 Unset complete

 Notice the Destroying right after the building? Is that normal
 behavior, i just updated to PHP 5.1.4 for windows and IMO its not
 normal, can anyone test this on PHP 5 for linux see if it's only a
 windows issue

 This is really important thanks

 Math
 

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



Re: [PHP] Re: Question about constructors and destructors

2006-06-28 Thread Richard Lynch
On Wed, June 28, 2006 5:07 pm, Jochem Maas wrote:
 zend.ze1_compatibility_mode is next to useless in practice for
 anything
 but the most simple php4 OO code. certainly if you are wanting to
 use php5 specific OO functionality like __destruct() you should not be
 using
 ze1_compatibility_mode.

My understanding of ze1_compatibility_mode is:

Run this code as if I was using PHP4 OOP with none of PHP5 features
so I can keep my legacy app running even though I have PHP5
installed.

I do not think it is (nor can be)

Magically determine through DWIM-technology what weird mix of PHP4
OOP and PHP5 OOP the programmer has decided should be implemented

So I suspect it would work fine for even complicated PHP4 OOP code,
but as soon as you expect to use a PHP5 OOP feature, results would
be... unpredictable

:-)

But that's just my understanding of what I would expect this setting
to mean.  I could be way off-base.

YMMV

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Re: Question about constructors and destructors

2006-06-28 Thread Jochem Maas
Richard Lynch wrote:
 On Wed, June 28, 2006 5:07 pm, Jochem Maas wrote:
 zend.ze1_compatibility_mode is next to useless in practice for
 anything
 but the most simple php4 OO code. certainly if you are wanting to
 use php5 specific OO functionality like __destruct() you should not be
 using
 ze1_compatibility_mode.
 
 My understanding of ze1_compatibility_mode is:
 
 Run this code as if I was using PHP4 OOP with none of PHP5 features
 so I can keep my legacy app running even though I have PHP5
 installed.
 
 I do not think it is (nor can be)
 
 Magically determine through DWIM-technology what weird mix of PHP4
 OOP and PHP5 OOP the programmer has decided should be implemented

:-) if they remarketed  DWIM(tm) as OnAWhim(tm) it might catch on.

 
 So I suspect it would work fine for even complicated PHP4 OOP code,
 but as soon as you expect to use a PHP5 OOP feature, results would
 be... unpredictable
 
 :-)
 
 But that's just my understanding of what I would expect this setting
 to mean.  I could be way off-base.

great expectations (free pun included) but my experience is that it's not
a bed of roses in practice ... I get the impression the implementation of
ze1_compatibility_mode is a total nightmare (and not a priority either)...
that said complicated php4 OO code has a tendency to not 'work fine' even when
you stick to php4 ;-)


 
 YMMV
 

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