From: [EMAIL PROTECTED] Operating system: Windows 2000 PHP version: 4.2.3 PHP Bug Type: Scripting Engine problem Bug description: Lost object variables during execution of a register_shutdown_function
I'm running php4.2.3 on apache/1.3.24(w2k) as a module. This are my two classes: (Explanations see below) <? class A { function init() { register_shutdown_function(array(&$this, 'flush')); } function flush() { 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; } } $d = new B('/path/to/logs/debugger.messages'); $d->log('text one'); $d->log('text ten'); ?> I would like to call the flush()-method on shutdown that the logs could be written to file. So I register it in the init()-method with register_shutdown_function(array(&$this, 'flush')) and the init()-method is called from the constructor of class B. I expected that the $this->logs array would be available and I could write it to a file. But the variable was always empty and the sizeof() returns 0. Do I call the flush()-method manually at the end of the script, everything works like expected. Every variable set in the constructor B(), like $this->file, is available in the flush()-method called by the registered shutdown function. Every variable set later does not exist. Is that a bug? or just misscoding... -- Edit bug report at http://bugs.php.net/?id=19519&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=19519&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=19519&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=19519&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=19519&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=19519&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=19519&r=support Expected behavior: http://bugs.php.net/fix.php?id=19519&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=19519&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=19519&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=19519&r=globals