#34665 [Opn->Fbk]: Incompatibility between references and the __destruct() method

From: Date: Tue, 27 Sep 2005 20:02:05 +0000
Subject: #34665 [Opn->Fbk]: Incompatibility between references and the __destruct() method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-85677@lists.php.net to get a copy of this message
 ID:               34665
 Updated by:       tony2001@php.net
 Reported By:      sliver373 at hotmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Class/Object related
 Operating System: Windows & Linux
 PHP Version:      5.0.5
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Can't reproduce with 5.0.6-dev and 5.1-dev. 


Previous Comments:
------------------------------------------------------------------------

[2005-09-27 21:39:48] sliver373 at hotmail dot com

Description:
------------
I found an incompatibility between the __destruct() fonction and the
references.
When assigning your object (which countains __destruct() ) using
references ($myObject =& new TheObject();) for the second time (or
more), the second object will be deleted just like the first and your
variable will countain only the NULL value.
Look at the code...

Excuse me for my english, but I'm french, and I hope you'll understand
;-)

Reproduce code:
---------------
class TheObject {

  function __construct() {
    echo "__construct()...\n";
  }

  function __destruct() {
    echo "__destruct()...\n";
  }

}

echo "<pre>";
$myObject =& new TheObject();
var_dump($myObject); // => a TheObject object
$myObject =& new TheObject();
var_dump($myObject); // => NULL !!!!
echo "</pre>";

Expected result:
----------------
I'd like to see this output :

__construct()...
object(TheObject)#1 (0) {
}
__destruct()...
__construct()...
object(TheObject)#2 (0) {
}
__destruct()...


or this one will work too :

__construct()...
object(TheObject)#1 (0) {
}
__construct()...
__destruct()...
object(TheObject)#2 (0) {
}
__destruct()...


Actual result:
--------------
But I see this output :
__construct()...
object(TheObject)#1 (0) {
}
__construct()...
__destruct()...
__destruct()...
NULL

The automatic call of the __destruct() fonction on the seconde
assignment destruct the both objects !
So the second assignment doesn't work !!!

Thanks you for all you'll be able to do ;)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34665&edit=1


Thread (2 messages)

« previous php.bugs (#85677) next »