php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19519 Lost object variables during execution of a register_shutdown_function
Submitted: 2002-09-20 04:20 UTC Modified: 2002-10-06 06:58 UTC
From: natz at bluewin dot ch Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.2.3 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: natz at bluewin dot ch
New email:
PHP Version: OS:

 

 [2002-09-20 04:20 UTC] natz at bluewin dot ch
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...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-06 06:58 UTC] natz at bluewin dot ch
sorry!!!

there is just a '&' needed:

$d = & new B('/path/to/logs/debugger.messages');
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Apr 05 01:01:24 2020 UTC