hi
I'm running php 4.2.3 as a module on a w2k apache/1.3.24. And I got any troubles with using register_shutdown_function.
This is my code:
class A {
function init() {
register_shutdown_function(array(&$this, 'out'));
}
flush flush() {
var_dumb($this); //dumb 2
if(sizeof($this->logs) > 0) {
/* Write it to a file */
}
}
}
class B extends A {
function B($file) {
$this->file = $file;
$this->init();
}
function log($msg) {
$this->logs[] = $msg;
}
}
$b = new B('/path/to/logs/debugger.messages');
$b->log('text one');
// ....
$b->log('text ten');
var_dumb($b); //dumb 1
The problem now is, that the flush function looses the $this->logs variable if it's called on shutdown. that means, the sizeof() is always 0. Do I call flush() manually, everything works fine. Every variable set in the constucter BBB is in the flush method available. every variable set later does not exist.
The var_dump output of
- dumb 1 is:
object(b)(2) {
["file"]=>
string(31) "/path/to/logs/debugger.messages"
["logs"]=>
array(2) {
[0]=>
string(8) "text one"
[1]=>
string(8) "text ten"
}
}
- dump 2
object(b)(1) {
["file"]=>
string(31) "/path/to/logs/debugger.messages"
}
Is it impossible to register a function of a inherited class in register_shutdown? Or is it just a bug.
Thanx for any hints.
Marcel