I hear you...
In pure OO programming, the purpose of a destructor method is not to delete the object, it is a function that is called when the object is deleted; in much the same way that the constructor is called when the object is new()'d. That is, if some code external to the object deletes the object, the destructor is called prior to the object's actual removal. This is useful for doing cleanup, recovery, messaging, etc upon the event that caused the object to be destroyed.
Even if this type of destructor is not possible or not deemed useful, it would be nice to be able to at least create my own destructor:
class myClass
{
var $myProperty;
// constructor
function myClass()
{
// initialize some stuff
$this->myProperty = "";
}
function destroy()
{
// do some cleanup
// destroy myself
unset($this); // doesn't work!
}
}
$myObject = New myClass;
$myObject->destroy(); // does not unset the object
...in fact, I can't even create a non-object function to delete an object:
function destroyObject(&$obj)
{
$obj->destroy(); // do some cleanup
unset($obj); // try to get rid of it
}
$myObject = new myClass;
destroyObject($myObject); // still doesn't destroy the object
I even tried GLOBALizing the object and using var-var's, but the only way I can accomplish some cleanup functionality and destroy an object is:
$myObject = new myClass;
$myObject->destroy();
unset($myObject); // only works here
Now, I have not done enough research to say there is a bug, but I would think that either of the first two methods should have worked. Especially the second with the object GLOBALized.
(sigh)