Req #60738 [PATCH]: Allow 'set_error_handler' to handle NULL
| From: | nikic@php.net | Date: | Fri, 23 Mar 2012 20:50:45 +0000 |
| Subject: | Req #60738 [PATCH]: Allow 'set_error_handler' to handle NULL | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168780@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60738&edit=1
ID: 60738
Patch added by: nikic@php.net
Reported by: four dot zerooneunauthorized at gmail dot com
Summary: Allow 'set_error_handler' to handle NULL
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: irrelivant
PHP Version: 5.3.9
Block user comment: N
Private report: N
New Comment:
The following patch has been added/updated:
Patch Name: error_handler_patch_1.diff
Revision: 1332535845
URL: https://bugs.php.net/patch-display.php?bug=60738&patch=error_handler_patch_1.diff&revision=1332535845
Previous Comments:
------------------------------------------------------------------------
[2012-03-13 08:56:27] kevin dot swinton at gmail dot com
In the first instance, nothing in here relates to a bug, rather both are feature requests.
The first request is for set_error_handler() to function in an identical way to
set_exception_handler() when called with a single NULL parameter. In the interests of a more
consistent API this would seem sensible.
The second request is for set_exception_handler() (and by extension set_error_handler()) to behave
in a different way when called with a single NULL parameter.
Given there is no compelling argument, and that such a change could technically break BC, and that
the request in itself doesn't appear to achieve anything useful, the suggestion would be that
the first request could be implemented whilst the second request has no case.
As a result, I have attached a patch to implement only the first request.
------------------------------------------------------------------------
[2012-01-13 02:22:55] four dot zerooneunauthorized at gmail dot com
Description:
------------
Can the 'set_error_handler' function be made to accept NULL as the parameter in such a way
as to reset this feature to the default state of -no- handler being set? This would duplicate the
behavior of the 'set_exception_handler' function.
Note: this change should not interfere with the 'restore_error_handler' function.
And as for the 'set_exception_handler' function - if NULL is given as a parameter, can the
return value of 'set_exception_handler' be set to the details of the previously set
exception handler function (string or array) instead of always '(bool) true' as it now
does?
Test script:
---------------
function testhandler1($errno= null, $errstr= null, $errfile= null, $errline = null)
{
error_log('1: ' . print_r(func_get_args(), true));
die();
}
function testhandler2($errno= null, $errstr= null, $errfile= null, $errline = null)
{
error_log('2: ' . print_r(func_get_args(), true));
die();
}
var_dump(set_error_handler('testhandler1'));
var_dump(set_error_handler('testhandler2'));
var_dump(set_error_handler(null));
Expected result:
----------------
NULL
string(12) "testhandler1"
string(12) "testhandler2"
Actual result:
--------------
On line 'var_dump(set_error_handler(null));', a 'set_error_handler() expects the
argument () to be a valid callback' error is generated and handled by function
"testhandler2"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60738&edit=1