#38572 [NEW]: Destructor may be called before all references to it are gone

From: Date: Wed, 23 Aug 2006 19:40:51 +0000
Subject: #38572 [NEW]: Destructor may be called before all references to it are gone
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969373817@lists.php.net to get a copy of this message
From: richardkmiller at gmail dot com Operating system: tested on Mac OS X and Windows PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: Destructor may be called before all references to it are gone Description: ------------ The documentation for PHP 5 destructors (http://php.net/ manual/en/language.oop5.decon.php) says "The destructor method will be called as soon as all references to a particular object are removed..." but this may not always be true. In PHP 5.1, the mysqli object is destroyed before the destructor of my class which refers to it, so I can't make mysqli calls from my destructor. Reproduce code: --------------- <?php $db = new mysqli('localhost', USERNAME, PASSWORD, DATABASE); class Test { public function __construct() { global $db; $db->query("SELECT 'test'"); } public function __destruct() { global $db; $db->query("SELECT 'test'"); // line 15 } } $test = new Test(); ?> Expected result: ---------------- I expect this code to produce no errors (no output). Actual result: -------------- This code produces the following warning: Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli in test.php on line 15 This bug appears to have been documented at #31326 and #36034. If it isn't planned to be fixed, the documentation should be updated to read the following (quoting helly@php.net from #36034): "You cannot rely on any order of destruction in shutdown sequence. All you can do is ensuring yourself that all related variables are set NULL or are being unset() prior to script end. If you do that in correct order then php calls the destructors in correct order." -- Edit bug report at http://bugs.php.net/?id=38572&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38572&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38572&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38572&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38572&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38572&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38572&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38572&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38572&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38572&r=support Expected behavior: http://bugs.php.net/fix.php?id=38572&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38572&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38572&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38572&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38572&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38572&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38572&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38572&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38572&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38572&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38572&r=mysqlcfg

« previous php.doc (#969373817) next »