#30447 [NEW]: Static functions called from a destructor don't have access to the object

From: Date: Fri, 15 Oct 2004 14:11:52 +0000
Subject: #30447 [NEW]: Static functions called from a destructor don't have access to the object
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-67623@lists.php.net to get a copy of this message
From: arend at auton dot nl Operating system: Linux PHP version: 5.0.2 PHP Bug Type: Zend Engine 2 problem Bug description: Static functions called from a destructor don't have access to the object Description: ------------ If you use singleton classes, it is often handy to have one global instance of your class and manipulate this instance using static functions. Then it can also be handy to call such a static function for cleanup purposes inside the destructor. However, if the object is cleaned up using unset(), the static functions lose access to the global instance before the destructor is finished. If the instance just runs out of scope, it works normally however. Btw, this bug seems somewhat similar to Bug #29685 in which it also appears the destructor is called too late with a singleton pattern, with the exception that this code does not have a private instance and simply uses a global instance. Reproduce code: --------------- class Test { public function __construct() { $this->a = "test"; } public function __destruct() { self::printA(); } static public function printA() { global $test; echo "$test->a\n"; } private $a; } $test = new Test; unset($test); Expected result: ---------------- It should print: "test". Actual result: -------------- It prints nothing. -- Edit bug report at http://bugs.php.net/?id=30447&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30447&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30447&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30447&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=30447&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=30447&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=30447&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=30447&r=needscript Try newer version: http://bugs.php.net/fix.php?id=30447&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=30447&r=support Expected behavior: http://bugs.php.net/fix.php?id=30447&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=30447&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=30447&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=30447&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30447&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=30447&r=dst IIS Stability: http://bugs.php.net/fix.php?id=30447&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=30447&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=30447&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=30447&r=mysqlcfg

« previous php.bugs (#67623) next »