|
From: K. O. <web...@my...> - 2003-07-11 09:17:36
|
I guess we'd better stick with using the trigger_error function directly
otherwise we would need to pass the file name and line numbers explicitly
like
notice($msg, __FILE__, __LINE__); if we need to know where the error
occurred exactly and that doesn't seem to make things any easier for the
developers..
- Kazu
----- Original Message -----
From: "K. Ono" <web...@my...>
To: <xoo...@li...>
Sent: Thursday, July 10, 2003 4:21 PM
Subject: Re: [Xoops-development] addressing "blank page" problem
> > Or maybe this: Leave the error handler always ON. If debug mode is on,
> > show all errors and warnings (native PHP messages AND explicitly
> > 'triggered' messages). If debug mode is off, show only 'triggered'
> > messages. If we use trigger_error very sparingly (or E_USER_ERROR for
> > errors-to-be-displayed) then the end user will only see a message if
> > something goes very wrong (e.g. can't connect to database), which may be
> > useful to alert the site administrator. (In a custom error handler you
> > can strip out any path info so this is not a security risk.)
>
> I like this idea.. Maybe we can wrap the trigger_error() function with a
> custom function/class so that we
> can always call the custom trigger error function/method within the codes
> which does
> not always call the native trigger_error function. This way, the coders
> wouldn't need to
> think about whether to use the native trigger_error() function in certain
> areas of their
> codes but just always use the custom one wherever something wrong might
> happen.
>
> For example,
>
>
> class ErrorHandler
> {
>
> function ErrorHandler()
> {
> set_error_handler(array(&$this, 'trigger'));
> }
>
> function trigger($errno, $errstr, $errfile, $errline)
> {
> switch ($errno) {
> case E_USER_ERROR:
> // do something here
> break;
> case E_USER_WARNING:
> // do something here
> break;
> case E_USER_NOTICE:
> // do something here
> break;
> default:
> // do something here
> break;
> }
>
> }
>
> // A class that triggers all errors
> class ShowAllErrorHandler extends ErrorHandler
> {
>
> function notice($msg)
> {
> trigger_error(E_USER_NOTICE, $msg);
> }
>
> function warning($msg)
> {
> trigger_error(E_USER_WARNING, $msg);
> }
>
> function fatal($msg)
> {
> trigger_error(E_USER_ERROR, $msg);
> }
> }
>
> // A class that triggers only fatal-level errors
> class FatalErrorHandler extends ErrorHandler
> {
> function notice($msg)
> {
> // do nothing
> }
>
> function warning($msg)
> {
> // do nothing
> }
>
> function fatal($msg)
> {
> trigger_error(E_USER_ERROR, $msg);
> }
> }
>
>
> And at startup, we can use a factory method/class to create one of the
error
> handler classes
> depending on a config setting or the user level (admin, anonymous, etc).
>
> $debug_level = $xoopsUser->isAdmin() ? XOOPS_DEBUG_SHOWALL :
> $config['debug_level'];
> $error_handler =& ErrorHandler::getInstance($debug_level);
> ...
> $error_handler->notice('A notice error');
> ...
|