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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php