php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35101 A custom handler set with set_error_handler() cannot be unset/removed
Submitted: 2005-11-04 09:13 UTC Modified: 2006-11-11 01:24 UTC
From: mfischer@php.net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 6CVS OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mfischer@php.net
New email:
PHP Version: OS:

 

 [2005-11-04 09:13 UTC] mfischer@php.net
Description:
------------
A custom error handler set with set_error_handler() cannot be removed.

The documentation says that the return value of set_error_handler() is the previous error handler. In case of no previous error handler, NULL is returned.

However set_error_handler() cannot be called with NULL to restore the PHP default error handler. This results in the following:

$ php -r 'set_error_handler(NULL);'
Warning: set_error_handler() expects argument 1, '', to be a valid callback in Command line code on line 1


Reproduce code:
---------------
<?php
    function handler() {
        echo "called\n";
    }

    set_error_handler('handler called');
    set_error_handler();
?>


Expected result:
----------------
Somehow a way for removing the current error handler and restoring the original behaviour should be possible.

Actual result:
--------------
handler called

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-04 09:16 UTC] derick@php.net
Nowhere it says that this is possible, thus marking it as a Feature Request.
 [2006-01-10 16:34 UTC] jon at fuck dot org
well restore_error_handler() works in 5.1.1.. so what happened?

code:
<?
function foo() { echo 'foo'; }
set_error_handler('foo');
z;
restore_error_handler();
f;
?>

output:
jon@ac-dev-sv1 ~ $ php -f foo.php
foo
Notice: Use of undefined constant f - assumed 'f' in /home/jon/foo.php on line 7
 [2006-11-11 01:24 UTC] tony2001@php.net
There is restore_error_handler() for that matter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC