0

Introduction

I am getting strange error in zf2. I don't know why, but I am getting some routing error. I don't get any messages, but needed controller is not loaded, but another one do. All looking fine, so it is not good idea to ask here to help me to solve this problem, so I am trying to debug this by myself.


What I have tried?

I tried debug_backtrace() function in /public/index.php file like this:

// Setup autoloading
require 'init_autoloader.php';

// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();

var_dump(debug_backtrace());

It shows nothing.

Just to check if function is working I tried:

function bob() {
    var_dump(debug_backtrace());
}

bob();

And this showed me what params were passed, what functions called etc. This showed me, that function is executed correctly, but this function is not used in my case.


Question

Is there any ways to get what functions was executed in app?

AliciaBytes
  • 7,300
  • 6
  • 36
  • 47
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87

2 Answers2

1

I think you slightly misunderstand what debug_backtrace() does. It lists the function calls that led to the place in code where the backtrace is. So in your bob() example, it will show that function (as bob() was called). But if you just call debug_backtrace() in public/index.php, that's not executed within any functions, which is why you don't get any output.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
  • Thank you. But I am not sure your question is answer to the question. The question was `Is there any ways to get what functions was executed in app?`. Your suggestion might be a comment, but not answer. Thank you anyway — you clarified how `debug_backtrace()` works. – Sharikov Vladislav May 23 '14 at 17:36
  • Fair point. I'm not sure if there's a PHP function that would give you that list, although you could certainly do it with Xdebug. However in this case I don't think that would help you debug your problem. There would be literally thousands of function calls in ZF, probably 10s of thousands. If you want to post details about the routing error you're trying to fix (perhaps in a separate question), we might be able to help with that instead. – Tim Fountain May 23 '14 at 17:39
  • Well, I solved problem... I am thinking about deleting this question but I am not sure. It is still open. For example, me or somebody else, will get error which he doesn't know how to solve and he doesn't know what cause this error. It will be good to know, that you know how to debug what route was chosen and by what. In my case, if I had knew what route was chosen and why, I would have solved my problem much more faster. Sorry for my bad english. Did you understand me? Anyway voted up, because you clarified how function works. – Sharikov Vladislav May 23 '14 at 17:44
0

I am not sure how reasonable it will be for you to install a different stack, but ZendServer has code tracing/profiling built in and that is exactly what you are looking for.

Victory
  • 5,811
  • 2
  • 26
  • 45