2

I have PHP 5.3.4 and when I try to use debug_print_backtrace, I don't get anything. When I use vardump, I get an empty array, as you can see below.

index.php:

<?php
define('WP_USE_THEMES', true);

require('./wp-blog-header.php');

var_dump(debug_backtrace());

echo PHP_VERSION;
?>

which returns

...
</html> 
array(0) {
}
5.3.4

Can anyone tell me what is wrong? I am expecting to see everything that was called in the run. Instead I don't see anything.

Arlen Beiler
  • 15,336
  • 34
  • 92
  • 135

2 Answers2

7

debug_backtrace() doesn't show you what has been called so far but the current call stack (i.e. more or less where php would jump to on a return statement until it reaches the top level) when the function is invoked.
You might be interested in a profiler like e.g. the one implemented in XDebug plus something to analyse the data like e.g. kcachegrind.

VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • 1
    If you're in the very first PHP document loaded by your application, i.e. not in a function or include file, you can echo `__FILE__` and `__LINE__` to output the current file name and line number. – Michael Butler Feb 01 '12 at 15:40
  • For anyone seeing this page when using it properly and still not getting expected results: http://stackoverflow.com/questions/1252529/get-code-line-and-file-thats-executing-the-current-function-in-php – Dissident Rage Mar 12 '14 at 15:48
2

If you're really after Code Coverage (which it sounds like from your description) then XDebug is useful, or see the responses to this SO question

Community
  • 1
  • 1
Mark Baker
  • 209,507
  • 32
  • 346
  • 385