Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81493 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43384 invoked from network); 31 Jan 2015 17:40:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2015 17:40:43 -0000 Authentication-Results: pb1.pair.com header.from=mails@thomasbley.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=mails@thomasbley.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain thomasbley.de from 85.13.137.24 cause and error) X-PHP-List-Original-Sender: mails@thomasbley.de X-Host-Fingerprint: 85.13.137.24 dd15934.kasserver.com Received: from [85.13.137.24] ([85.13.137.24:54565] helo=dd15934.kasserver.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/70-39884-8931DC45 for ; Sat, 31 Jan 2015 12:40:41 -0500 Received: from dd15934.kasserver.com (dd0800.kasserver.com [85.13.143.204]) by dd15934.kasserver.com (Postfix) with ESMTPSA id 4B1EB26187F; Sat, 31 Jan 2015 18:40:37 +0100 (CET) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-SenderIP: 95.90.237.26 User-Agent: ALL-INKL Webmail 2.11 In-Reply-To: References: <20150121043939.5129B26183A@dd15934.kasserver.com> To: danack@basereality.com Cc: internals@lists.php.net, yohgaki@ohgaki.net Message-ID: <20150131174037.4B1EB26187F@dd15934.kasserver.com> Date: Sat, 31 Jan 2015 18:40:37 +0100 (CET) Subject: Re: [PHP-DEV] Enable error_handler callback parameters to be passed by reference From: mails@thomasbley.de ("Thomas Bley") error_log() is a good point. In the future, set_error_handler() might be changed to be called multiple times with different custom error handlers, similar to how register_shutdown_function() and spl_autoload_register() act on multiple calls. Having a chain of error handlers appending data to $errstr makes it difficult to use error_log(), because this is a one-time operation. Also, error_log() has the ability to override the "error_log" property from php.ini, which might not be the desired behaviour. So I would prefer $errstr to be passed by reference. For completeness, error_log() currently has no parameters for $errno, $line and $file, so an example would look like this: function myErrorHandler($errno, $errstr, $errfile, $errline) { switch($errno){ case E_WARNING: $errnoStr='Warning'; break; case E_NOTICE: $errnoStr='Notice'; break; case E_STRICT: $errnoStr='Strict'; break; case E_RECOVERABLE_ERROR: $errnoStr='Recoverable Error'; break; case E_DEPRECATED: $errnoStr='Deprecated'; break; case E_USER_ERROR: $errnoStr='User Error'; break; case E_USER_WARNING: $errnoStr='User Warning'; break; case E_USER_NOTICE: $errnoStr='User Notice'; break; case E_USER_DEPRECATED: $errnoStr='User Deprecated'; break; } if (!empty($_SESSION['username'])) { $errstr .= ', username: '.$_SESSION['username']; } error_log('PHP '.$errnoStr.': '.$errstr.' in '.$errfile.' on line '.$errline); return true; } Regards Thomas Dan Ackroyd wrote on 30.01.2015 10:38: > On 21 January 2015 at 04:39, Thomas Bley wrote: >> In userland it is sometimes necessary to extend PHP's notices/warnings with >> additional information (e.g. username from session, stack trace, etc.) > > Why can't you just use in the error handler function to write the > exact message you want? > > http://php.net/manual/en/function.error-log.php > > cheers > Dan >