Re: Enable error_handler callback parameters to be passed by reference

From: Date: Thu, 22 Jan 2015 10:41:46 +0000
Subject: Re: Enable error_handler callback parameters to be passed by reference
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-80970@lists.php.net to get a copy of this message
Hi Thomas, On Wed, Jan 21, 2015 at 1:39 PM, Thomas Bley <mails@thomasbley.de> wrote: > In userland it is sometimes necessary to extend PHP's notices/warnings > with additional information (e.g. username from session, stack trace, etc.) > I'm proposing to enable error_handler callback parameters to be passed by > reference to be able to append additional data to error messages. > > Example: > > <?php > ini_set('error_reporting', E_ALL); > ini_set('display_errors', 0); > ini_set('log_errors', 1); > ini_set('error_log', 'php_error.log'); > > function myErrorHandler($errno, &$errstr, $errfile, $errline) { > if (!empty($_SESSION['username'])) { > $errstr .= ', username: '.$_SESSION['username']; > } > return false; // continue normal error handler > } > > set_error_handler("myErrorHandler"); > > function test() { > echo tests; // Use of undefined constant tests > } > > test(); > > Gives in php_error.log: > [21-Jan-2015 04:32:26 UTC] PHP Notice: Use of undefined constant tests - > assumed 'tests', username: ... in error.php on line 17 > > Instead of: > [21-Jan-2015 04:32:26 UTC] PHP Notice: Use of undefined constant tests - > assumed 'tests' in error.php on line 17 > This would be very useful for accounting! If you cannot send pull requests, please file this to bugs.php.net as request. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net

« previous php.internals (#80970) next »