|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27903 Undesired behavior of class destructor
Submitted: 2004-04-07 07:04 UTC Modified: 2004-09-02 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: schroeter at liquidvision dot net Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.0.0RC1 OS: Winn2000 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
6 + 39 = ?
Subscribe to this entry?

 [2004-04-07 07:04 UTC] schroeter at liquidvision dot net
The __destruct() method seems buggy as the destructor is called after some system internals are already cleaned up (e.g. mysql extension, session etc.).
Thus it is impossible to set e.g. session data in the destructor, leaving this mostly superfluous!

I have prepared an example that shows the point in detail.

This is also true for e.g. mysql_close() in the destructor!

Reproduce code:

Expected result:
Please see comments in file.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-07 07:57 UTC]
You need to redesign your stuff, the destructor works just fine. (don't misuse it like you did)

 [2004-04-07 09:11 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is correct behavior, nothing we can fix most likely here for PHP 5.0.
 [2004-04-07 09:11 UTC] schroeter at liquidvision dot net

1. I disagree that this behavior is the way it should be. It does not make sense to me that internal stuff is cleaned up before the user defined stuff is?! 

2. If it will remain this way, it has to made clear in the docs. 

3. I found a workaround that will solve this:

just place a 

register_shutdown_function(array(&$this, 'your class function'));

at the end of the __constructor function -this will give the desired functionality.

I hope that will remain in future releases.


 [2004-08-25 03:21 UTC] alvaro at utahgateway dot com
I have to agree with schroeter.
Is there a reason why you can't call the code in the dtors before shutting down the sessions.
 [2004-09-02 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: Thu May 30 05:01:31 2024 UTC