Re: Enable error_handler callback parameters to be passed by reference
| From: | Thomas Bley | Date: | Fri, 23 Jan 2015 07:46:27 +0000 |
| Subject: | Re: Enable error_handler callback parameters to be passed by reference | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81028@lists.php.net to get a copy of this message | ||
Thanks I'll draft a RFC during the weekend.
Regards
Thomas
reeze wrote on 22.01.2015 17:01:
> I like the idea, we have the similar scenario, we need to print request log id to the log,
>
>
> so I just made a PR to implement this:
> https://github.com/php/php-src/pull/1018
> <https://github.com/php/php-src/pull/1018> the PR is against
> master,
>
> but I think this could also been in 5.5.
>
>
> On 22 January 2015 at 18:41, Yasuo Ohgaki <yohgaki@ohgaki.net
> <mailto:yohgaki@ohgaki.net> > wrote:
>> Hi Thomas,
>>
>>
>> On Wed, Jan 21, 2015 at 1:39 PM, Thomas Bley <mails@thomasbley.de
>> <mailto: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
>> <http://bugs.php.net> as
>> request.
>>
>> Regards,
>>
>> --
>> Yasuo Ohgaki
>> yohgaki@ohgaki.net <mailto:yohgaki@ohgaki.net>
>
>