php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25128 set_error_handler not sending reference
Submitted: 2003-08-18 09:22 UTC Modified: 2003-08-18 10:31 UTC
From: auroraeosrose at hotmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4CVS-2003-08-18 (stable) OS: Win XP Pro SP1
Private report: No CVE-ID: None
 [2003-08-18 09:22 UTC] auroraeosrose at hotmail dot com
Description:
------------
Latest cvs snapshot of 4.3.whatever we're at now.  When sending an object/method array for a set_error_handler, the object is not being referenced, I have no idea what it's doing.

I'd like to be able to change stuff in the object I have the error handler in before an error is triggered...

This may be a dupe of #22894 but I'm not sure since that one wasn't explained very well...

Reproduce code:
---------------
<?
class Stack
{
	var $stack;

	function Stack()
	{
		$this->stack = array();
		set_error_handler(array(&$this, 'errorHandler'));
	}

	function push($message)
	{
		$this->stack[] = $message;
		print_r($this); //for debugging
	}

	function errorHandler($code, $message, $file, $line, $context)
	{
		$this->push($message);
	}

}

$e = new Stack();
$e->push('This is a fun test');
trigger_error('This is a test', E_USER_NOTICE);

?>

Expected result:
----------------
stack Object
(
    [stack] => Array
        (
            [0] => This is a fun test
        )

)
stack Object
(
    [stack] => Array
        (
            [0] => This is fun a test
            [1] => This is a test
        )

)

Actual result:
--------------
stack Object
(
    [stack] => Array
        (
            [0] => This is a fun test
        )

)
stack Object
(
    [stack] => Array
        (
            [0] => This is a test
        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-18 09:37 UTC] sniper@php.net
If you use the trigger_error() twice, it'll push the messages into the array just fine. Not bug.

 [2003-08-18 10:04 UTC] auroraeosrose at hotmail dot com
You're missing the point, I want to send a referenced object and be able to change things it before I trigger an error...another test

<?
class Stack
{
	var $stack;
	var $debug;

	function Stack()
	{
		$this->stack = array();
		$this->debug = false;
		set_error_handler(array(&$this, 'errorHandler'));
	}

	function push($message)
	{
		$this->stack[] = $message;
		print_r($this); //for debugging
	}

	function errorHandler($code, $message, $file, $line, $context)
	{
		$this->push($message);
	}

}

$e = new Stack();
$e->debug = true;
trigger_error('This is a test', E_USER_NOTICE);

?>

Now, notice I've changed debug before I triggered the error, so when I do my print_r of $this it should have debug set to true, because I changed it, but notice it's still set to false
 [2003-08-18 10:21 UTC] auroraeosrose at hotmail dot com
BTW if this is the desired behavior, that you can't manipulate an error handler class after assigning it, that should be in BIG BOLD LETTERS in the documentation
 [2003-08-18 10:31 UTC] sniper@php.net
Just move the set_error_handler() outside the class.
(after you init the object)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 05 22:01:26 2024 UTC