php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46196 restore_error_handler() broken
Submitted: 2008-09-29 12:37 UTC Modified: 2008-11-25 18:25 UTC
Votes:10
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:5 (83.3%)
Same OS:5 (83.3%)
From: php at benjaminschulz dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3CVS-2008-11-11 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at benjaminschulz dot com
New email:
PHP Version: OS:

 

 [2008-09-29 12:37 UTC] php at benjaminschulz dot com
Description:
------------
restore_error_handler doesn't work anymore in PHP 5.3.0alpha3-dev (cli) (built: Sep 29 2008 12:17:38)

Reproduce code:
---------------
function foo() { var_dump(__FUNCTION__); } 
set_error_handler("foo"); 
restore_error_handler(); 
trigger_error("foobar", E_USER_ERROR);'

Expected result:
----------------
A standard error message.

Actual result:
--------------
string(3) "foo"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-31 16:05 UTC] olivier at ajeux dot com
Same bug encountered with php5.3-200810301330, also with a php crash.

Reproduce code:
---------------
<?php

var_dump ( set_error_handler ('myErrorHandler') );
restore_error_handler  ();
var_dump ( set_error_handler ('myErrorHandler') );

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    return true;
}

Expected result:
----------------
NULL
NULL

Actual result:
--------------
NULL
string(14) "myErrorHandler"
zend_mm_heap corrupted
 [2008-11-11 10:42 UTC] jani@php.net
Works fine with PHP_5_2, does not with PHP_5_3. 
 [2008-11-13 17:22 UTC] webmaster at ajeux dot com
I have tested tagged version in CVS:
php_5_3_0alpha1: OK (no bug)
php_5_3_0alpha2: ERROR (bug happened).

So, it seems this bug was introduced between alpha1 and alpha2.

If you give me a way to export cvs at a precise date, I can adjust when and where this bug was commited.
 [2008-11-14 16:59 UTC] olivier at ajeux dot com
I tested several export from CVS and I found when was commited the bug: 
2008-08-11 17:00 GMT: OK (no bug)
2008-08-11 17:30 GMT: ERROR (bug happened).

Script used for information:
$ cvs -d :pserver:cvsread@cvs.php.net:/repository checkout -r PHP_5_3 -D"2008-08-11 17:30 GMT" php-src
$ cd php-src
$ ./buildconf --force && ./configure && make

I hope it can help. This is a major bug for me.
 [2008-11-17 10:59 UTC] webmaster at ajeux dot com
I made a patch to fix this bug and tested it *successfully* on php5.3-200811170930 (latest snap as I'm writing).

I am not an expert in diff/patch, so syntax may be wrong.

--- Zend/zend_API.c     2008-11-17 11:02:39.000000000 +0100
+++ Zend/zend_API.c     2008-08-08 19:47:28.000000000 +0200
@@ -3467,10 +3467,6 @@
 {
        current->handling = EG(error_handling);
        current->exception = EG(exception_class);
-       current->user_handler = EG(user_error_handler);
-       if (current->user_handler) {
-               Z_ADDREF_P(current->user_handler);
-       }
 }
 /* }}} */

@@ -3478,10 +3474,6 @@
 {
        if (current) {
                zend_save_error_handling(current TSRMLS_CC);
-               if (error_handling != EH_NORMAL && EG(user_error_handler)) {
-                       zval_ptr_dtor(&EG(user_error_handler));
-                       EG(user_error_handler) = NULL;
-               }
        }
        EG(error_handling) = error_handling;
        EG(exception_class) = error_handling == EH_THROW ? exception_class : NULL;
@@ -3499,15 +3491,6 @@
 {
        EG(error_handling) = saved->handling;
        EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
-       if (saved->user_handler && saved->user_handler != EG(user_error_handler)) {
-               if (EG(user_error_handler)) {
-                       zval_ptr_dtor(&EG(user_error_handler));
-               }
-               EG(user_error_handler) = saved->user_handler;
-       } else if (saved->user_handler) {
-               zval_ptr_dtor(&saved->user_handler);
-       }
-       saved->user_handler = NULL;
 }
 /* }}} */
 [2008-11-17 11:17 UTC] webmaster at ajeux dot com
It seems my diff patch failed to apply on some configurations.
Here is full functions altered in Zend/zend_API.C (end of file, three functions modified):

ZEND_API void zend_save_error_handling(zend_error_handling *current TSRMLS_DC) /* {{{ */
{
        current->handling = EG(error_handling);
        current->exception = EG(exception_class);
}
/* }}} */

ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, zend_class_entry *exception_class, zend_error_handling *current TSRMLS_DC) /* {{{ */
{
        if (current) {
                zend_save_error_handling(current TSRMLS_CC);
        }
        EG(error_handling) = error_handling;
        EG(exception_class) = error_handling == EH_THROW ? exception_class : NULL;
}
/* }}} */

ZEND_API void zend_restore_error_handling(zend_error_handling *saved TSRMLS_DC) /* {{{ */
{
        EG(error_handling) = saved->handling;
        EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
}
/* }}} */
 [2008-11-25 09:42 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I can not reproduce this anymore using latest CVS.
 [2008-11-25 16:56 UTC] webmaster at ajeux dot com
The bug seems to be fixed (tested successfully with php5.3-200811251530 on Linux).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC