This is a discussion on Re: Notice errors with set_error_handler within the PHP Language forums, part of the PHP Programming Forums category; Hi John! On Thu, 24 Jul 2003 20:03:08 +0200, "JohnVT" <johnN0SPAM@foobar.nl> wrote: &...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi John!
On Thu, 24 Jul 2003 20:03:08 +0200, "JohnVT" <johnN0SPAM@foobar.nl> wrote: >(Crossposted from alt.comp.lang.php) > >Questions in comments. > >Thanks you. > >Greetings, > > - John > ><? >error_reporting (E_ALL); > >function myErrorHandler($errno, $errstr, $errfile, $errline) { > echo "<br>Error number $errno \"$errstr\" in $errfile on line >$errline.<br>"; >} > >$x = $a; >@$x = $b; > >set_error_handler("myErrorHandler"); >$x = $c; >@$x = $d; > >/* > >Displays: > >Notice: Undefined variable: a in >c:\data\htdocs\projects\photobook\testerror.php on line 8 >Error number 8 "Undefined variable: c" in >c:\data\htdocs\projects\photobook\testerror.php on line 11. >Error number 8 "Undefined variable: d" in >c:\data\htdocs\projects\photobook\testerror.php on line 12. > >1) Why does it fall over @$x = $d (with my own error handler) and not over >@$x = $b with the standard error handler? What is the setting of error_reproting without your error_handler? >2) From the manual I understood only E_USER_* errors were handled by the >set_error_handler. Why is E_NOTICE given to myErrorHandler()? AFAIK, all errors, which are not fatal are given to the users error handler. You want to use it to handle errors of xxsql_functions, if there is a problem with the database for example. HTH, Jochen -- Jochen Daum - CANS Ltd. PHP DB Edit Toolkit -- PHP scripts for building database editing interfaces. http://sourceforge.net/projects/phpdbedittk/ |
|
|||
|
Thanks for your reply Jochen.
I understand error handling better now. I was wrong about the error types that are handled by your own error handler; E_USER_*, E_WARNING and E_NOTICE will be handled by your own handler, the others will be handled by the standard handler. About the other question: With set_error_handler() you bypass the standard error handler. The standard error handler exits after a fatal error, let you use @maybe_goes_wrong(), etc. So you'd have to take care of these things yourself in your own error handler. So when I use my own error handler and I try ... --- if (!($fp = @fopen('not_a_file', 'r'))) trigger_error("Can't open file!", E_USER_WARNING); --- .... I get ... --- Warning: fopen("not_a_file", "r") - No such file or directory in c:\data\htdocs\projects\photobook\newindex.php on line 19. User Warning : Can't open file! in c:\data\htdocs\projects\photobook\newindex.php on line 20. --- Any idea how to keep using @ with your own error handler? Thanks, - John "Jochen Daum" <jochen.daum@cans.co.nz> wrote in message news:evh0ivoq9rg8gve62tpimcjih2r8o4vd5d@4ax.com... > Hi John! > > On Thu, 24 Jul 2003 20:03:08 +0200, "JohnVT" <johnN0SPAM@foobar.nl> > wrote: > > >(Crossposted from alt.comp.lang.php) > > > >Questions in comments. > > > >Thanks you. > > > >Greetings, > > > > - John > > > ><? > >error_reporting (E_ALL); > > > >function myErrorHandler($errno, $errstr, $errfile, $errline) { > > echo "<br>Error number $errno \"$errstr\" in $errfile on line > >$errline.<br>"; > >} > > > >$x = $a; > >@$x = $b; > > > >set_error_handler("myErrorHandler"); > >$x = $c; > >@$x = $d; > > > >/* > > > >Displays: > > > >Notice: Undefined variable: a in > >c:\data\htdocs\projects\photobook\testerror.php on line 8 > >Error number 8 "Undefined variable: c" in > >c:\data\htdocs\projects\photobook\testerror.php on line 11. > >Error number 8 "Undefined variable: d" in > >c:\data\htdocs\projects\photobook\testerror.php on line 12. > > > >1) Why does it fall over @$x = $d (with my own error handler) and not over > >@$x = $b with the standard error handler? > > What is the setting of error_reproting without your error_handler? > > >2) From the manual I understood only E_USER_* errors were handled by the > >set_error_handler. Why is E_NOTICE given to myErrorHandler()? > > AFAIK, all errors, which are not fatal are given to the users error > handler. You want to use it to handle errors of xxsql_functions, if > there is a problem with the database for example. > > HTH, Jochen > > -- > Jochen Daum - CANS Ltd. > PHP DB Edit Toolkit -- PHP scripts for building > database editing interfaces. > http://sourceforge.net/projects/phpdbedittk/ |