# bug in set_error_handler

- Thread: https://externals.io/message/1522
- Original archive: https://news-web.php.net/php.internals/1522
- Started by walt boring on 2003-05-14T20:20:24+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #1522 — walt boring — 2003-05-14T20:20:24+00:00

URL: https://externals.io/message/1522#1522

Howdy,
  I hope this isn't too late to get in, but I found a problem in 
 `set_error_handler()` when trying to use an object method as an error handler.

I have a patch against php-4.3.1 for Zend/zend_builtin_functions.c

set_error_handler was assuming that the value passed in to the function 
was a string, and hence
the test for Z_STRLEN_PP(error_handler) was always 0 if it was called as 
follows

set_error_handler( array(&$this, "myhandler") );


This patch makes sure the type of the var error_handler is a string 
before testing the length
of the name.

My question is, why does this block RETURN_TRUE if we set
EG(user_error_handler) = NULL; ?  shouldn't we return false here?

Walt


[root@hemna src]# diff -u php-4.3.1/Zend/zend_builtin_functions.c 
php-4.3.1-walt/Zend/zend_builtin_functions.c
--- php-4.3.1/Zend/zend_builtin_functions.c     2002-11-27 
12:11:10.000000000 -0800
+++ php-4.3.1-walt/Zend/zend_builtin_functions.c        2003-05-14 
13:15:39.000000000 -0700
@@ -891,7 +891,8 @@
        }
        ALLOC_ZVAL(EG(user_error_handler));

-       if (Z_STRLEN_PP(error_handler)==0) { /* unset user-defined 
handler */
+    /* Make sure we test for an empty string on a non-array value here */
+       if (Z_TYPE_PP(error_handler) == IS_STRING && 
Z_STRLEN_PP(error_handler)==0) { /* unset user-defined handler */
                FREE_ZVAL(EG(user_error_handler));
                EG(user_error_handler) = NULL;
                RETURN_TRUE;
