note 15996 added to language.variables.scope
| From: | candrews at insight dot com | Date: | Thu, 11 Oct 2001 17:36:55 +0000 |
| Subject: | note 15996 added to language.variables.scope | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18833@lists.php.net to get a copy of this message | ||
In a large project recently undertaken, we have been using the PEAR virtual destructors.
We have been using a small code snippet to allow pseudo-singletons within the OO code:
class MyClass
{
function &getInstance()
{
static $instance = null;
if ($instance === null) {
$instance = new MyClass();
}
return $instance;
}
}
$myobj =& MyClass::getInstance();
However, this break PEAR destructors as $instance is created with new, rather than &new. If
&new is used to create the static variable, it is destroyed on function exit, and therefore is
null again the second time around.
--
http://www.php.net/manual/en/language.variables.scope.php
http://master.php.net/manage/user-notes.php?action=edit+15996
http://master.php.net/manage/user-notes.php?action=delete+15996
http://master.php.net/manage/user-notes.php?action=reject+15996