On Tue, 2002-06-11 at 22:01, Tom Rogers wrote:
> Hi
> A revised cleanup function for multiple instances of the same class.
>
> <?
> $ref = array();
> class cRoute{
> var $txt; //identify the class
> function cRoute($txt=""){
> global $ref;
> $x = count($ref); //get an index
> $this->txt = $txt;
> $ref[$x] =& $this; //setup a pointer
> //create a function
> $f_txt = 'global $ref;
> trigger_error("Please call close() to prevent
> problems, close() has been called for you.");
> $ref['.$x.']->close();';
> $func = create_function("",$f_txt);
> //register it
> register_shutdown_function($func);
> }
>
> function close(){
> //close open sockets, etc.
> mail("yourEmailHere",$this->txt."Callback","Function Close
called\n");
> }
> }
> $c1 = new cRoute("First:");
> $c2 = new cRoute("Second:");
> echo "exiting now <br>";
> ?>
>
> Tom
It's probably easier just to do it this way...less code to maintain
and no magic (although I like your solution too):
<?php
error_reporting(E_ALL);
class cRoute{
function cRoute(){
//register the shutdown function in case people who use this
//class dont call the appropiate close methods.
register_shutdown_function(array($this, 'cleanup'));
}
function cleanup(){
//cleanup.
trigger_error("Please call close() before the page ends, to
prevent problems close() has been called automatically for you.");
$this->close();
}
function close(){
echo "In close\n";
}
}
$one = new cRoute();
$two = new cRoute();
?>
--
Torben Wilson <[EMAIL PROTECTED]>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php