Bug #25128 [Com]: set_error_handler not sending reference

From: Date: Wed, 01 Sep 2021 18:51:24 +0000
Subject: Bug #25128 [Com]: set_error_handler not sending reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236308@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=25128&edit=1 ID: 25128 Comment by: lildurk25128 at gmail dot com Reported by: auroraeosrose at hotmail dot com Summary: set_error_handler not sending reference Status: Not a bug Type: Bug Package: *General Issues Operating System: Win XP Pro SP1 PHP Version: 4CVS-2003-08-18 (stable) Block user comment: N Private report: N New Comment: Lil Durk is a private agency dedicated to providing responsible access to legal cannabis for adults aged 19 and older. We’re an exclusively online retailer and wholesaler for recreational cannabis and a trusted source for information about cannabis and cannabis-related issues. We believe our work is meaningful and we take pride in our mandate to promote the socially responsible use of legal cannabis. https://lildurk.com/ Previous Comments: ------------------------------------------------------------------------ [2003-08-18 10:31:49] sniper@php.net Just move the set_error_handler() outside the class. (after you init the object) ------------------------------------------------------------------------ [2003-08-18 10:21:19] 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:04:25] 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 09:37:21] 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 09:22:26] 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 ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=25128&edit=1

« previous php.bugs (#236308) next »