Hi folks

An unusual problem (I think) with how to save state in an error class.

THE AIM is to consolodate PHP errors, user errors and failed asserts
into one common format, which can then be written to screen, logged,
emailed or written to a socket in any combination required.

THE MECHANISM is to a) register callbacks for the PHP generated errors
and assertions, and to b) put user errors into the php system with
trigger_error(), so PHP routes them to the error callback function.

The callback functions instantiate the error class and pass through
the parameters. The class then handles the error output and calls the
appropriate error handler.

THE ISSUE is that unlike a normal class, it may be called in the
background by the PHP error handler, so there is no calling function
to return a value to. Also, as the PHP errors are only WARNINGS and
NOTICES, the PHP error handler may call the class a number of times
during a single script. So as I understand it, any values stored in
the class properties will be lost as the class is re-instantiated.

So my question is this - given that the class can be called multiple
times in the background, how can state be saved so the application can
decide what action to take in response to the error?

The best I have come up with so far is to set a global constant:

function _set_error_state()
{
  if ( in_array( $this->error_number, $this->terminal_error_list ))
    {
      if ( !defined("REDIRECT_REQUIRED") && !DEBUGGING_ON )
      {
        define( "REDIRECT_REQUIRED", TRUE ) ;
      }
    }
}
This means that in production mode, the first terminal error
encountered will set a GLOBAL which can be accessed by the wider
application. The error handler is set in the same way.

This seems to work fine, but it feels like a bit of a hack. Is there a
better way to get this done?

I am very new to this game, so apologies in advance if any of this
doesn't make sense.

Thanks

Geoff Caplan
Caplan Associates



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to