首页 > 解决方案 > VSCode + Xdebug。逐步调试退出递归栈

问题描述

我正在使用VSCode + PHP + Xdebug。写了一个递归函数,试图调试它。但是当调试器到达堆栈的末尾“ return true ”时,它不会返回堆栈,它只是退出。我认为递归可能很糟糕。我用最简单的例子试过了,但还是一样。

例如:

function pow1($x, $n)
{
    if ($n == 1) {
        return $x;
    } else {
        return $x * pow1($x, $n - 1);
    }
}

$result = pow1(2, 3);

echo $result;

调试器达到return $x; 并以正确的结果退出堆栈。

pow1 (d:\OpenServer\OSPanel\domains\localhost\index.php:6)
pow1 (d:\OpenServer\OSPanel\domains\localhost\index.php:8)
pow1 (d:\OpenServer\OSPanel\domains\localhost\index.php:8)
{main} (d:\OpenServer\OSPanel\domains\localhost\index.php:12)

并跳到这里:

{main} (d:\OpenServer\OSPanel\domains\localhost\index.php:14)

我爬上了所有的 Xdebug 设置,尝试了不同的选项,但都没有帮助。将函数重写为JavaScript并在浏览器中调试。

标签: phprecursionvisual-studio-codexdebug

解决方案


推荐阅读