|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: sliver373 at hotmail dot com
New email:
PHP Version: OS:


 [2005-09-27 21:39 UTC] sliver373 at hotmail dot com
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 :

object(TheObject)#1 (0) {
object(TheObject)#2 (0) {

or this one will work too :

object(TheObject)#1 (0) {
object(TheObject)#2 (0) {

Actual result:
But I see this output :
object(TheObject)#1 (0) {

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 ;)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-27 22:02 UTC]
Please try using this CVS snapshot:
For Windows:

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: Sat May 25 21:01:29 2024 UTC