From:             sliver373 at hotmail dot com
Operating system: Windows & Linux
PHP version:      5.0.5
PHP Bug Type:     Class/Object related
Bug description:  Incompatibility between references and the __destruct() method

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 bug report at http://bugs.php.net/?id=34665&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34665&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34665&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34665&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=34665&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=34665&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=34665&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=34665&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=34665&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=34665&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=34665&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=34665&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=34665&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=34665&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34665&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=34665&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=34665&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=34665&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34665&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=34665&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34665&r=mysqlcfg

Reply via email to