This isn't necessarily a problem with Zend Framework, but I
encountered it while trying to beautify my PHP error screens using ZF
MVC. Here's the scenario:

I'm using the following code to generate exceptions when an error occurs in PHP:

if (!function_exists('exceptions_error_handler')) {
  function exceptions_error_handler($severity, 0, $errfile, $errline) {
    throw new ErrorException($errstr, 0, $severity, $errfile, $errline);
  }
}
set_error_handler('exceptions_error_handler', E_ALL);

Now, when an error occurs within one of my Controllers,
ErrorController will take over:

class IndexController extends Zend_Controller_Action {
  public function indexAction() {
    $foo->bar; // Uninitialized var
  }
}

In the view script for my error controller, I print out a nice,
formatted trace of the exception, using Exception::getTrace(). Here's
where I'm having the problem; exceptions generated from PHP errors
always have $trace[args] off by one. That is, each call entry in the
trace stack will have the function parameters for the previous call,
so, above will producea backtrace of:

function exceptions_error_handler()
IndexController::indexAction(String("indexAction"))
Zend_Controller_Action::dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
Zend_Controller_Dispatcher_Standard::dispatch()
Zend_Controller_Front::dispatch()

Notice indexAction("indexAction")... "indexAction" is should be in the
trace for the previous call:
Zend_Controller_Action::dispatch("indexAction") not
IndexController::indexAction(). I achieve the expected result when I
explicitly throw an exception:

class IndexController extends Zend_Controller_Action {
  public function indexAction() {
    throw new Exception("foobar!");
  }
}

Will produce a backtrace of:

IndexController::indexAction()
Zend_Controller_Action::dispatch(String("indexAction"))
Zend_Controller_Dispatcher_Standard::dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
Zend_Controller_Front::dispatch()

So my question is, Is this a known issue with debug_backtrace() and
exceptions thrown from set_error_handler() or am I missing something?

- jake

Reply via email to