note 37669 added to function.register-shutdown-function

From: Date: Sat, 22 Nov 2003 14:12:18 +0000
Subject: note 37669 added to function.register-shutdown-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-60812@lists.php.net to get a copy of this message
Response to => php at spandex dot deleteme dot nildram dot co dot uk 28-Apr-2003 07:43 I have checked the methods to implement destructors in classes and there is no requirement to use the syntax $oX = &new Class(); See the code below and try, what fits your PHP-requirements. I have tested with PHP 4.3.2 on Windows 2000. --8<--- cls_TEST.php --------------------------------------------->8-- <? // Class class TEST { var $Value; // Constructor function TEST($in_Value = 0){ // Register destructor register_shutdown_function(array(&$this, '_TEST')); $this->Value = $in_Value; $this->_Log('TEST'); } // Destructor function _TEST() { $this->_Log('_TEST'); } // Private function function _Log($in_Msg) { $oF = fopen('E:/temp/TEST.log', 'a'); fwrite($oF, sprintf("%s : %-5s = %d\n", date('Y-m-d H:i:s', time()), $in_Msg, $this->Value)); fclose($oF); } } ?> --8<--- test_TEST.php -------------------------------------------->8-- <? // include class TEST include_once('cls_TEST.php'); $o1 = new TEST(1); $o2 =& new TEST(2); $o3 &= new TEST(3); ?> --8<-------------------------------------------------------------->8-- It should produce a content like this in the file, specified in the _Log function : 2003-11-22 15:10:43 : TEST = 1 2003-11-22 15:10:43 : TEST = 2 2003-11-22 15:10:43 : TEST = 3 2003-11-22 15:10:43 : _TEST = 1 2003-11-22 15:10:43 : _TEST = 2 2003-11-22 15:10:43 : _TEST = 3 ---------------------------------------------------------------------- http://www.vbwebprofi.de ---- Manual Page -- http://www.php.net/manual/en/function.register-shutdown-function.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37669 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37669&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37669&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60812) next »