note 13885 deleted from language.oop by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 19:04:10 +0000 |
| Subject: | note 13885 deleted from language.oop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162574@lists.php.net to get a copy of this message | ||
Note Submitter: b dot ruecker at portunity dot de
----
If you need a destructor, perhaps it is an idear to simulate it this way with a global
Destroy-Function:
<?
function DestroyObject ($name)
{
$theobject = &$GLOBALS[$name];
if (method_exists ($theobject,"Destroy"))
$theobject->Destroy ();
unset ($GLOBALS[$name]);
}
class xyz
{
var $somevar;
// ### This is the constructor
function xyz ()
{
}
// ### This is the destructor which will be called
function Destroy ()
{
echo ("Now we destroy it !");
}
function SomeDo ()
{
echo ("doing something: ".$this->somevar);
}
}
$example = new xyz;
// .... doing something here
$example->somevar = 3;
$example->SomeDo();
DestroyObject ("example");
// ### Test => should produce an error !
$example->SomeDo ();
?>