php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60738 Allow 'set_error_handler' to handle NULL
Submitted: 2012-01-13 02:22 UTC Modified: 2012-09-28 04:09 UTC
From: four dot zerooneunauthorized at gmail dot com Assigned: laruence (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.3.9 OS: irrelivant
Private report: No CVE-ID: None
 [2012-01-13 02:22 UTC] 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"

Patches

bug60738.patch (last revision 2012-03-24 04:17 UTC by [email protected])
error_handler_patch_1.diff (last revision 2012-03-23 20:50 UTC by [email protected])
set_error_handler-allow-null-parameter-corrected (last revision 2012-03-11 07:46 UTC by kevin dot swinton at gmail dot com)
set_error_handler-allow-null-parameter (last revision 2012-03-10 22:34 UTC by kevin dot swinton at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-13 08:56 UTC] 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-03-23 20:50 UTC] [email protected]
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
 [2012-03-24 03:24 UTC] [email protected]
The following patch has been added/updated:

Patch Name: bug60738.patch
Revision:   1332559481
URL:        https://bugs.php.net/patch-display.php?bug=60738&patch=bug60738.patch&revision=1332559481
 [2012-03-24 03:26 UTC] [email protected]
Hi, I attached another fix, this will save one alloc/free pair, and also save one 
(IS_NULL == Z_TYPE_P(error_handler). 

Nikic,  if you have no objection, I will commit the patch.

thanks
 [2012-03-24 03:30 UTC] [email protected]
The following patch has been added/updated:

Patch Name: bug60738.patch
Revision:   1332559848
URL:        https://bugs.php.net/patch-display.php?bug=60738&patch=bug60738.patch&revision=1332559848
 [2012-03-24 03:32 UTC] [email protected]
The following patch has been added/updated:

Patch Name: bug60738.patch
Revision:   1332559920
URL:        https://bugs.php.net/patch-display.php?bug=60738&patch=bug60738.patch&revision=1332559920
 [2012-03-24 04:17 UTC] [email protected]
The following patch has been added/updated:

Patch Name: bug60738.patch
Revision:   1332562646
URL:        https://bugs.php.net/patch-display.php?bug=60738&patch=bug60738.patch&revision=1332562646
 [2012-03-24 06:37 UTC] [email protected]
-Assigned To: +Assigned To: laruence
 [2012-03-24 07:21 UTC] [email protected]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-03-24 07:21 UTC] [email protected]
-Status: Assigned +Status: Closed
 [2012-03-24 08:52 UTC] [email protected]
set_error_handler(null) should return old handler, not true - just as any other 
function does.
 [2012-03-24 08:52 UTC] [email protected]
-Status: Closed +Status: Re-Opened
 [2012-03-24 10:00 UTC] [email protected]
-Status: Re-Opened +Status: Closed
 [2012-03-24 10:00 UTC] [email protected]
As discussion at the pull request:
in the manual of set_exception_handler says:
   " Returns the name of the previously defined exception handler, or
NULL on error. If no previous handler was defined, NULL is also
returned. If NULL is passed, resetting the handler to its default
state, TRUE is returned. "

close this entry, change the return value should be another issue(FR)
 [2012-03-24 11:44 UTC] [email protected]
As Stas asked to revert it from 5.4,  so now only implement in trunk.
 [2012-03-24 11:44 UTC] [email protected]
-Status: Closed +Status: Re-Opened
 [2012-09-28 04:09 UTC] [email protected]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

nikic already commmitted the new implemention.
 [2012-09-28 04:09 UTC] [email protected]
-Status: Re-Opened +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jun 11 10:01:26 2025 UTC