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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sat Dec 21 18:01:29 2024 UTC