php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29372 destructor not called
Submitted: 2004-07-25 07:55 UTC Modified: 2004-07-25 21:08 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mark at seventhcycle dot net Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0 OS: *
Private report: No CVE-ID: None
 [2004-07-25 07:55 UTC] mark at seventhcycle dot net
Description:
------------
The destructor for any classes I make isn't being called.  Here is a diff of my php.ini to the distributed one.

/usr/local/lib#> diff php.ini php.ini-dist 
120c120
< zlib.output_compression = On
---
> zlib.output_compression = Off
293c293
< log_errors = On
---
> log_errors = Off
340c340
< error_log = syslog
---
> ;error_log = syslog
373c373
< register_globals = On
---
> register_globals = Off
952c952
< session.use_trans_sid = 1
---
> session.use_trans_sid = 0


The reproduced code run below is live here:
http://seventhcycle.net/php/classtest.php

A copy of my phpinfo can be found here:
http://seventhcycle.net/php/phpinfo.php

Reproduce code:
---------------
<?php
class MyDestructableClass {
   function __construct() {
       print "construct\n";
   }

   function __destruct() {
       print "destruct";
   }
}

$obj = new MyDestructableClass();
?> 

Expected result:
----------------
construct
destruct

Actual result:
--------------
construct

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-25 08:29 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You cannot use print, echo and friends in destructors because they are executed after the output facility has been shutdown. Use unset($obj) at the end of your script to force termination prior to starting shutdown process.
 [2004-07-25 20:58 UTC] mark at seventhcycle dot net
Interestingly, this follows the same behavior as register_shutdown_function() does in php5, in that it can't send anything out to the browser.

php4 can do this, though, and does properly print shutdown information.

function shut()
{  
  echo "shutting down";
}
 [2004-07-25 21:00 UTC] mark at seventhcycle dot net
Sorry, the proper code posted would be:

function shut()
{  
  echo "shutting down";
}

register_shutdown_function("shut");

This prints out properly in php4.  Is it a bug in php4, or a change of functionality for php5?
 [2004-07-25 21:08 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Whatever...this is fixed in cvs for 5.0.1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 23:01:29 2024 UTC