red888
red888

Reputation: 31694

ZF2: How to always show a stack trace

With ZF2 I get a stack trace when something goes wrong, but for learning purposes I'd sometime like to see a stack trace when things go right. Can I make a call to something that will poop out a stack trace on the page regardless of errors?

Also, are there any good tutorials on reading\understanding the stack traces? Sorry for the double question, but didn't think my second question deserved its own post.

Upvotes: 0

Views: 643

Answers (2)

jmleroux
jmleroux

Reputation: 947

You can also use ZendDeveloperTools

It's a great help for developer.

Upvotes: 0

AlexP
AlexP

Reputation: 9857

You can generate similar information that would be available when an exception is thrown using debug_backtrace().

In a ZF2 app this might give you too much information (and it is also in array format). I wrote a very simple function that I just chucked into my local.php to aid debugging; it might be of some help.

function debug_light_trace()
{
    $backtrace = "Backtrace :-\n";
    $debug_backtrace = debug_backtrace();

    array_shift($debug_backtrace);

    foreach ($debug_backtrace as $trace) {
        $class      = (isset($trace['class']))?$trace['class']:'';
        $function   = (isset($trace['function']))?$trace['function']:'';
        $file       = (isset($trace['file']))?$trace['file']:'';
        $APP_ROOT   = dirname(dirname(__DIR__));
        $file       = str_replace($APP_ROOT, '', $file);
        $line       = (isset($trace['line']))?$trace['line']:'';
        $backtrace .= "{$file}({$line}) - {$class}::{$function}()\n";
    }
    return $backtrace;
}

With regards to more information, the documentation would be a good place to start (and of Google searching). I very quickly scanned this tuts plus guide; which might also give you some more background.

Upvotes: 2

Related Questions