In php , is there a way to trace a variable?

懵懂的女人 提交于 2019-12-21 03:02:24

问题


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]


来源:https://stackoverflow.com/questions/29482637/in-php-is-there-a-way-to-trace-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!