Static Destructor methods
| From: | Richard Heyes | Date: | Fri, 05 Apr 2002 19:44:15 +0000 |
| Subject: | Static Destructor methods | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-5204@lists.php.net to get a copy of this message | ||
In the File class, which is soon to be entirely static based, there is a
need for a destructor style method which runs when the script is finished to
unlock locked files, and close open file pointers. Currently it's done by
using a File_shutDown() function which is registered, which in turn calls
File::_File().
What I'd like to suggest is a function in PEAR.php which can do this. For
example, at the bottom of File.php, outside the class, there'd be a call to:
PEAR::registerStaticShutdown($className, $methodName);
This function could in turn store the class/method combinations and call
them when required. It would require a call from _PEAR_call_destructors()
adding (eg. PEAR::registerStaticShutdown(null, null, true) ), and a possible
prototype for the function could be (as a method of class PEAR):
function registerStaticShutdown($class, $method, $shutdown = false)
{
static $staticDestructors;
if (!$shutdown) {
$staticDestructors[] = array('class' => $class, 'method' =>
$method);
} else {
foreach ($staticDestructors as $val) {
eval(sprintf('%s::%s;', $class, $method));
}
}
}
--
Richard Heyes
"If you have any trouble sounding condescending,
find a Unix user to show you how it's done." - Scott Adams