#30447 [Opn->Bgs]: Static functions called from a destructor don't have access to the object
| From: | tony2001@php.net | Date: | Thu, 13 Jan 2005 00:20:50 +0000 |
| Subject: | #30447 [Opn->Bgs]: Static functions called from a destructor don't have access to the object | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-71999@lists.php.net to get a copy of this message | ||
ID: 30447
Updated by: tony2001@php.net
Reported By: arend at auton dot nl
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: Linux
PHP Version: 5.0.2
New Comment:
No bug here:
"Because static methods are callable without an instance of the object
created, the pseudo variable $this is not available inside the method
declared as static."
http://php.net/manual/en/language.oop5.static.php
Previous Comments:
------------------------------------------------------------------------
[2004-10-15 16:11:47] arend at auton dot nl
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 this bug report at http://bugs.php.net/?id=30447&edit=1