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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sliver373 at hotmail dot com
New email:
PHP Version: OS:

 

 [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-2023 The PHP Group
All rights reserved.
Last updated: Tue Mar 21 06:03:41 2023 UTC