note 37669 deleted from function.register-shutdown-function by nlopess

From: Date: Thu, 09 Nov 2006 21:56:39 +0000
Subject: note 37669 deleted from function.register-shutdown-function by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119572@lists.php.net to get a copy of this message
Note Submitter: vbwebprofi at gmx dot de ---- 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

« previous php.notes (#119572) next »