PhpStorm中Xdebug的条件断点
假设我们有以下两种方法:PhpStorm中Xdebug的条件断点,php,phpstorm,Php,Phpstorm,假设我们有以下两种方法: function superFunction($superhero,array $clothes){ if($superhero===CHUCK_NORRIS){ wear($clothes); } else if($superhero===SUPERMAN) { wear($clothes[1]); } } function wear(array $clothes) { for($piece in $clothe
function superFunction($superhero,array $clothes){
if($superhero===CHUCK_NORRIS){
wear($clothes);
} else if($superhero===SUPERMAN) {
wear($clothes[1]);
}
}
function wear(array $clothes)
{
for($piece in $clothes){
echo "Wearing piece";
}
}
因此,我想要实现的是在PhpStorm中将断点放入函数
wear
,但我只想在$superhero
变量的值为CHUCK_NORRIS
时被解雇。假设函数superFunction
被调用了无数次,而一直按F9键会适得其反。正如我所评论的,至少有两种可能的方法可以实现这一点:
function superFunction($superhero, array $clothes)
{
if ($superhero === CHUCK_NORRIS){
wear($clothes); // <---- put the break point on this line
} elseif ($superhero === SUPERMAN) {
wear($clothes[1]);
}
}
function superFunction($superhero,array $clothes)
{
if ($superhero === CHUCK_NORRIS) {
wear($clothes, $superhero); // <---- passing the $superhero variable
} elseif ($superhero === SUPERMAN) {
wear($clothes[1]);
}
}
function wear(array $clothes, $superhero = null)
{
for ($piece in $clothes) { // <---- conditional break point here: $superhero === CHUCK_NORRIS
echo "Wearing piece";
}
}
像往常一样将断点放在PhpStorm中,然后右键单击编辑器槽中标记断点的红色光盘。在打开的弹出窗口中,输入希望断点停止脚本执行的条件。可以在此处输入在放置断点的代码中有效的任何条件 例如,输入
$superhero===CHUCK_NORRIS
按“完成”按钮,就可以开始了。像往常一样调试脚本。每次命中断点时,调试器都会计算该条件,但只有当该条件的计算结果为
true
时,调试器才会停止脚本(在if语句中)将断点放在函数调用上然后进入函数…..或将$superhero值作为参数传递给wear函数,并在断点上添加一个条件,仅当$superhero参数为CHUCK_NORRIS时停止执行“是将断点放入函数wear
中,但我只想在$superhero
变量具有该值时被解雇”--由于$superhero
不在功能范围内,因此无法工作。你必须照@MateiMihai说的去做。