我在 Visual Studio Code 中使用插件 PHP Debugger 来调试 PHP 代码。 PHP <= 5.6 一切正常。调试器就像一个魅力。 但是当我尝试使用 PHP 7 调试代码时,它并没有按预期工作。 它不会跳到我添加的断点,我被困在了 thousand excepton 之类的
Exception has occurred. Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; RecurringType has a deprecated constructor
或者
Exception has occurred. Warning: Declaration of AntlrLexer::matchAny() should be compatible with BaseRecognizer::matchAny($input)
或者
Exception has occurred. Notice: Trying to get property of non-object
这些异常是由框架生成的,所以我无法修复它们,我只想跳过所有这些异常并只跳转到我的断点。
我怎样才能做到这一点? 谢谢。
最佳答案
我不知道这是否适用于您的配置(我将 PHP 7.2 与 WordPress 一起使用),并且发现如果我只想这样做,它可以防止 XDebug 触发每个异常、警告、通知等单步执行我自己的代码部分。
首先,取消选中 Breakpoints
调试部分中的所有内容(包括 Everything
,如果已选中):
然后将鼠标悬停在 Breakpoints
栏上并单击 +
:
现在添加要调试的函数的名称:
最后,在该函数中设置一个断点。您现在将能够仅在该函数内触发 XDebug 分步执行:
据推测,您可以根据需要添加任意数量的您自己的函数断点。有趣的是,如果您有多个同名函数,您只需添加一次函数名称。
关于VSCODE : how to ignore exceptions 中的 PHP 7 Xdebug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51758284/