Re: [PHP] set_error_handler() Keeps Triggering Errors
On Sun, 10 Nov 2002 10:48:46 -0500, you wrote: >Hi Earnest. I found these user notes in the PHP manual, but, it's confusing >and seems to be a bit contradictory: It's simple: A user defined error handler cannot handle parse errors or compile time errors. That makes sense to me...if your script doesn't parse and can't complete the compile phase then how would you expect your custom function to be able to handle the error? It hasn't been compiled yet... >I just can't get this to >work after having tried some other things I found online. All I want is for >PHP to NOT report E_NOTICE errors, but, there seems to be no way to do this, >even if I re-define the E_NOTICE constant vars. The answer is in the editor's note that you quoted, two paragraphs after you snipped the quote: "if (!($type & error_reporting())) return;" $type is the error code..i.e. the first parameter passed to your error handler. Add that line to the top of your error handling function and it will behave the way you expect. PHP's error reporting value is a bitmask...a combination of all of the error type constants that you want PHP to report. The line of code above takes the current error's bit value and does a bitwise AND with the error reporting level. If the result is 0, that means that the current error's bit value is not turned on in the current error reporting level. If this is so, then the line above will return from your error handling function without doing anything...effectively ignoring the error. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] set_error_handler() Keeps Triggering Errors
Hi Earnest. I found these user notes in the PHP manual, but, it's confusing and seems to be a bit contradictory: -[snip]- error_reporting() has no effect if you have defined your own error handler with set_error_handler() [Editor's Note: This is not quite accurate. E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR and E_COMPILE_WARNING error levels will be handled as per the error_reporting settings. All other levels of errors will be passed to the custom error handler defined by set_error_handler(). -[/snip]- PHP's error-handling seems to need to re-working. I just can't get this to work after having tried some other things I found online. All I want is for PHP to NOT report E_NOTICE errors, but, there seems to be no way to do this, even if I re-define the E_NOTICE constant vars. Thanks. > From: [EMAIL PROTECTED] (Ernest E Vogelsinger) > Newsgroups: php.general > Date: Sun, 10 Nov 2002 10:42:05 +0100 > To: Monty <[EMAIL PROTECTED]> > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] set_error_handler() Keeps Triggering Errors > > At 06:34 10.11.2002, Monty said: > [snip] >> When I use set_error_handler('error_function') in my scripts, errors are >> constantly being triggered that I've never seen before. If I comment the >> handler function out, the errors go away. I have the error reporting set >> very loosely: error_reporting (E_ERROR | E_USER_ERROR) - so not sure why it > > It's somewhere in the docs - can't remember where just now, I believe > isomewhere in the user comments for error_handler: > > your error_handler gets _all_ type of error,warning,notice, regardless of > the actual setting of error_reporting (which only decides if the > error/warning/notice gets sent to the client or not). > >> keeps triggering an error, because the error I keep getting is: >> >> Undefined variable: target >> >> This is the same error message no matter what script I run. I don't even use >> a variable named $target anywhere in any of my scripts, so, this is >> baffling. And this seems like an E_NOTICE error message, but, I'm only >> asking for E_ERROR and E_USER_ERROR notices. > [snip] > > Might point to a dynamic variable named target: > > error_reporting(E_ALL); > $varname = 'target'; > if ($$varname) { > ; > } > ?> > > > gets me > Notice: Undefined variable: target in /www/test/test.php on line 4 > > Do a grep for "target" on your source files. > > > -- >> O Ernest E. Vogelsinger > (\)ICQ #13394035 > ^ http://www.vogelsinger.at/ > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] set_error_handler() Keeps Triggering Errors
At 06:34 10.11.2002, Monty said: [snip] >When I use set_error_handler('error_function') in my scripts, errors are >constantly being triggered that I've never seen before. If I comment the >handler function out, the errors go away. I have the error reporting set >very loosely: error_reporting (E_ERROR | E_USER_ERROR) - so not sure why it It's somewhere in the docs - can't remember where just now, I believe isomewhere in the user comments for error_handler: your error_handler gets _all_ type of error,warning,notice, regardless of the actual setting of error_reporting (which only decides if the error/warning/notice gets sent to the client or not). >keeps triggering an error, because the error I keep getting is: > >Undefined variable: target > >This is the same error message no matter what script I run. I don't even use >a variable named $target anywhere in any of my scripts, so, this is >baffling. And this seems like an E_NOTICE error message, but, I'm only >asking for E_ERROR and E_USER_ERROR notices. [snip] Might point to a dynamic variable named target: gets me Notice: Undefined variable: target in /www/test/test.php on line 4 Do a grep for "target" on your source files. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] set_error_handler() Keeps Triggering Errors
When I use set_error_handler('error_function') in my scripts, errors are constantly being triggered that I've never seen before. If I comment the handler function out, the errors go away. I have the error reporting set very loosely: error_reporting (E_ERROR | E_USER_ERROR) - so not sure why it keeps triggering an error, because the error I keep getting is: Undefined variable: target This is the same error message no matter what script I run. I don't even use a variable named $target anywhere in any of my scripts, so, this is baffling. And this seems like an E_NOTICE error message, but, I'm only asking for E_ERROR and E_USER_ERROR notices. My error handling function is fairly simple. It just loads the error info in a session var then sends the user to the error page, which reads the error info from the session vars and displays it. function show_error($type, $msg, $file, $line, $context) { // Setup error message in Session var... $_SESSION['error']['type'] = $type; $_SESSION['error']['msg'] = $msg; $_SESSION['error']['file'] = $file; $_SESSION['error']['line'] = $line; header("Location:./error_page.php"); } Anyone have any clues why when I set_error_handler to the above function errors are being triggered for every page? Monty -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php