php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34665 Incompatibility between references and the __destruct() method
Submitted: 2005-09-27 21:39 UTC Modified: 2005-10-05 01:00 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sliver373 at hotmail dot com Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.0.5 OS: Windows & Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-09-27 21:39 UTC] 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 ;)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-27 22:02 UTC] tony2001@php.net
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. 
 [2005-10-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 13:01:35 2024 UTC