|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62344 Class instance unset when running __destruct
Submitted: 2012-06-17 18:09 UTC Modified: 2021-01-15 14:14 UTC
From: minghanwu at yahoo dot com Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.14 OS: Debian 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: minghanwu at yahoo dot com
New email:
PHP Version: OS:


 [2012-06-17 18:09 UTC] minghanwu at yahoo dot com
I use a code like below on a server with php 5.1.6 for long, and the expected 
result below is the ACTUAL output of the code. 

Recently I have a new server running 5.3.3 and no luck. 

The point is the class instance is not able to be referenced when it runs to 
__destruct(). I use some functions to help object cleaning easier.

Any comment or help will be appreciated.

Test script:
class Database {
function __destruct() {
echo "Destroyed Database\n";

class Session {
private $db;
function __construct() {
$this->db = new Database();
function __destruct() {
echo "Destroyed Session\n";
} }

$sess = new Session();


function check(){
global $sess;
if(isset($sess)) echo "yes\n";
else echo "no\n";

Expected result:
Destroyed Session
Destroyed Database

Actual result:
Destroyed Session
Destroyed Database


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-15 14:14 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-01-15 14:14 UTC]
This is apparently fixed as of PHP 7.0.0[1].

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jun 24 10:01:23 2021 UTC