From:             paul dot liversidge at recycledpixels dot com
Operating system: Windows XP
PHP version:      4.3.2
PHP Bug Type:     Class/Object related
Bug description:  set_error_handler to a class/method resets class properties when 
error occurs

Description:
------------
I set the error handler to point at a class/method and then change some of
the class variables. Debugging lines and method confirm the class variable
has occurred. When I then trigger an error by echo'ing an uninitialized
variable the error handler resets or reinstantiates the class.

If $use_me is initialized in the constructor instead of being defined as a
'constant', it makes no difference as the value at the time of an error is
NULL, whatever is defined in the core class code.

If the set_error_handler function is called from line 3, i.e.
set_error_handler (array (&$err, 'handler_error')), it all works fine.

Reproduce code:
---------------
<?
$err = new ErrorHandler;

$err->use_me = true;
echo ("[1:{$err->use_me}]");
$err->test ();

echo $fred;

class ErrorHandler {
  var $use_me = 4;
  
  function ErrorHandler () { 
    set_error_handler (array (&$this, 'handle_error'));
  }  

  function test () {
    echo ("[2:{$this->use_me}]");
  }  

  function handle_error ($number, $message, $file, $line, $context) {
    echo ("[3:{$this->use_me}]");
    echo ("Error $number");
  }  
}
?>

Expected result:
----------------
[1:1][2:1][3:1]Error 8

Actual result:
--------------
[1:1][2:1][3:4]Error 8

-- 
Edit bug report at http://bugs.php.net/?id=25580&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=25580&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=25580&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=25580&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=25580&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=25580&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=25580&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=25580&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=25580&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=25580&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=25580&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=25580&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25580&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=25580&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=25580&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=25580&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25580&r=float

Reply via email to