# Make Zend give you a stack trace (the dirty way)

I.’m learning the Zend Framework and so have been working my way through the quickstart tutorial, modifying it slightly so that the example being set up broadly resembles the application I want to develop. The quickstart has you set up a basic Sqlite database table and render all the entries in that table. Problem for me: the entries weren’t showing up! Not only that, but the not-very-helpful error message that I got was simply “Application Error,” which means nothing. The frustrating thing was that everywhere I looked for help, it seemed like people were getting full stack traces printed to the screen! Why wasn’t the stack trace showing up for MY application, I wanted to know!

So, if you’re having the same problem – Zend tells you there’s an error but doesn’t bother to print the stack trace to the screen (actually, kind of a good idea in production, but not in development!) – I’m sure this isn’t any kind of ideal solution, but it worked for me.

Go to your ErrorController.php file (for a standard Zend project it’s application/controllers/ErrorController.php). Somewhere in there is a bit that looks like this:

 if ($this->getInvokeArg('displayExceptions') == true) {$this->view->exception = $errors->exception; }  That was the hint I needed. Obviously the better way to do this is to find some way to set $this->getInvokeArg('displayExceptions') to true, but I wasn’t finding an easy link on how to do that, so I cheated and just copied the internals intoglobal scope. Which is to say, I copied the line $this->view->exception =$errors->exception; outside of the curly braces, like so:

 if ($this->getInvokeArg('displayExceptions') == true) {$this->view->exception = $errors->exception; }$this->view->exception = \$errors->exception; 

I got a stack trace, which showed me that I had forgotten to include the primary key variable in my list of protected member variables in my model class. Once that was set, everything functioned as required.

Anyway, I’m clueless as to why Zend (apparently) comes with stack trace display available but disabled out of the box, and while I suspect that I will soon stumble upon how to enable it, for now this dirty little hack served my needs. It is, of course, REALLY important to remember to erase that line before deploying, should you use this workaround. Which you shouldn’t. Figure out how to do it right instead.

## One thought on “Make Zend give you a stack trace (the dirty way)”

1. Dan says:

Not sure if you ever got to the bottom of this, but it’s down to the ‘environment’ you’re application is in.
In your /configs/application.ini you can set which parameters apply to which environment the ‘site’ is in: allowing you to use different settings for dev, testing, staging and production (etc.). Each section can inherit from another.
I set it in my production environment so that instead of dumping the sensitive information (stack, variables, etc.) it emails it to a specific address instead (by including an email command in the ‘if’ statement from your example in ErrorController.