I have this variable in a big php script that I want to trace back to where/when and what value it was instantiated. Is there a function/api or debugging techniques to do this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If you're using PHPStorm you can set breakpoints and inspect the values of variables.
http://blog.jetbrains.com/phpstorm/2013/12/just-in-time-debugging-and-php-exception-breakpoints-with-phpstorm-and-xdebug/
You'll need xdebug installed as well.
回答2:
You can use debug_print_backtrace() function. http://php.net/manual/en/function.debug-print-backtrace.php
<?php
function f1() {
f2();
}
function f2() {
f3();
}
function f3(){
echo "<pre>";
debug_print_backtrace();
echo "</pre>";
}
f1();
?>
Output:
#0 f3() called at [/home/xfiddlec/public_html/main/code_47406510.php:9]
#1 f2() called at [/home/xfiddlec/public_html/main/code_47406510.php:5]
#2 f1() called at [/home/xfiddlec/public_html/main/code_47406510.php:18]