Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1554 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66086 invoked from network); 16 May 2003 01:35:48 -0000 Received: from unknown (HELO cs181147.pp.htv.fi) (213.243.181.147) by pb1.pair.com with SMTP; 16 May 2003 01:35:48 -0000 Received: from localhost (jani@localhost) by cs181147.pp.htv.fi (8.11.6/8.11.6) with ESMTP id h4G1Zmc21145; Fri, 16 May 2003 04:35:48 +0300 X-Authentication-Warning: cs181147.pp.htv.fi: jani owned process doing -bs Date: Fri, 16 May 2003 04:35:48 +0300 (EEST) Sender: jani@cs181147.pp.htv.fi Reply-To: Jani Taskinen To: walt boring cc: internals@lists.php.net In-Reply-To: <3EC43A1D.1040203@3gstech.com> Message-ID: References: <3EC43A1D.1040203@3gstech.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] bug in set_error_handler From: sniper@iki.fi (Jani Taskinen) Disclaimer: It worked fine for me. :) (I have huge configure line, I'm trying to figure out currently what caused it to work, even when it shouldn't..) Simple ./configure --disable-all produced a php binary that shows the symptom described in the bug report. The last patch is ok, that part of the code in zend_builtin_functions.c seems to have been forgotten there by Andrei, who added support of object methods for set_error_handler(). --Jani p.s. This is not critical bug, the fix will be in next release, 4.3.3 along with couple of dozen other fixes that didn't make it into 4.3.2. On Thu, 15 May 2003, walt boring wrote: >Howdy, > It seems the patch to fix the set_error_handler() didn't make it in >the RC3 build. > >set_error_handler( array(&$this, "errorhandler")) is broken. > >This bug is also described in http://bugs.php.net/?id=23619 > >but it seems that the only intelligent response from sniper@php.net > seems to be >"this patch is bogus" and fails to explain himself at all. This is not >very productive, and is not helping to solve the issue. > > I have tried it in php 4.3.1 and php 4.3.2 RC2 and RC3. It doesn't >work. I have provided a very simple php script which shows the >problem. the TestError::error() method is never called, and it should >be. You can comment the TestError error handler out, and use the >global_error() function and see it working. > >It is a very simple bug. set_error_handler() assumes that the param >passed in is a string, and tries to test the string the length, which is >bogus in the case of it being an array. Z_STRLEN_PP of an array? > > >ini_set("error_reporting" , E_ALL); >ini_set("display_errors", true); > >// This handler works >function global_error($errno, $errstr, $errfile, $errline) { > echo("global_error HANDLER CALLED (".$errstr.")\n"); >} > >class TestError { > function TestError() { > > //This set_error_handler does not work. > //it returns TRUE (which is wrong, because it never is set) > $res = set_error_handler(array(&$this, "error")); > echo("set_error_handler::error done retcode =" . >var_export($res, true) . "\n"); > } > > //This handler FAILS to be called. > function error($errno, $errstr, $errfile, $errline) { > echo("TestError::error HANDLER CALLED (".$errstr.")\n"); > } > > function runTest() { > $bar = $foo; > } >} > >$t = new TestError(); >//uncomment and use this handler to see it working. >//$res = set_error_handler("global_error"); >//echo("set_error_handler::global_error done retcode =" . >var_export($res, true) . "\n"); >$t->runTest(); >?> > > > > >The TestError::error handler fails to ever be called without the patch I >provided, because >set_error_handler() on line 894 >... > if (Z_STRLEN_PP(error_handler)==0) { /* unset user-defined handler */ > FREE_ZVAL(EG(user_error_handler)); > EG(user_error_handler) = NULL; > RETURN_TRUE; > } >... >it assumes error_handler zval is a string. It is an array. Clearly >doing a Z_STRLEN_PP on an array is completely wrong, and causes this to >fall through. Why are we returning TRUE in this case anyways, and isn't >this error case handled in the is_callable() check anyway? This code is >broken, and will never work in its current state. > >It should include a test to make sure its a string before trying to see >what the string length is! > > > 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; > } > >This prevents the test of the string length unless its actually a >string! go figure. > > >Walt > > > -- <- For Sale! ->