note 37915 added to function.register-shutdown-function
| From: | www dot php dot net at spam dot monnard dot org | Date: | Tue, 02 Dec 2003 03:26:25 +0000 |
| Subject: | note 37915 added to function.register-shutdown-function | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61247@lists.php.net to get a copy of this message | ||
Response to => vbwebprofi at gmx dot de 22-Nov-2003 03:12
You have to do a changement on the object to see the difference between = and =&
Here is your code modified to see the difference.
The modification of the code are essentially the var $Value_changed and the function change().
I have tested it under RedHat 9 with PHP 4.2.2
--8<--- cls_TEST.php --------------------------------------------->8--
<?php
class TEST {
var $Value;
var $Value_changed;
// Constructor
function TEST($in_Value = 0){
// Register destructor
register_shutdown_function(array(&$this, '_TEST'));
$this->Value = $in_Value;
$this->Value_changed = $in_Value;
$this->_Log('TEST');
}
// Destructor
function _TEST() {
$this->_Log('_TEST');
}
// Private function
function _Log($in_Msg) {
$oF = fopen('/tmp/TEST.log', 'a');
fwrite($oF, sprintf("%s : %-5s = %d ; %d\n",
date('Y-m-d H:i:s', time()),
$in_Msg,
$this->Value,
$this->Value_changed));
fclose($oF);
}
// Function change()
function change() {
$this->Value_changed++;
$this->_Log('change');
}
}
?>
--8<--- test_TEST.php -------------------------------------------->8--
<?php
// include class TEST
include_once('cls_TEST.php');
echo "New...<br>\n";
$o1 = new TEST(1);
$o2 =& new TEST(2);
# Strange declaration :
$o3 &= new TEST(3);
echo "Sleep...<br>\n";
sleep(5);
echo "Change...<br>\n";
$o1->change();
$o2->change();
# The following line doesn't work !
#$o3->change();
echo "Sleep...<br>\n";
sleep(5);
echo "End.";
?>
--8<-------------------------------------------------------------->8--
It should produce a content like this in the file, specified in the _Log function :
2003-12-02 04:22:55 : TEST = 1 ; 1
2003-12-02 04:22:55 : TEST = 2 ; 2
2003-12-02 04:22:55 : TEST = 3 ; 3
2003-12-02 04:23:01 : change = 1 ; 2
2003-12-02 04:23:01 : change = 2 ; 3
2003-12-02 04:23:06 : _TEST = 1 ; 1
2003-12-02 04:23:06 : _TEST = 2 ; 3
2003-12-02 04:23:06 : _TEST = 3 ; 3
----
Manual Page -- http://www.php.net/manual/en/function.register-shutdown-function.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37915
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37915&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37915&report=yes
Search -- http://master.php.net/manage/user-notes.php