Enable error_handler callback parameters to be passed by reference

From: Date: Wed, 21 Jan 2015 04:39:39 +0000
Subject: Enable error_handler callback parameters to be passed by reference
Groups: php.internals 
Request: Send a blank email to internals+get-80921@lists.php.net to get a copy of this message
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 Regards Thomas

« previous php.internals (#80921) next »