Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional breakpoints for Xdebug in PhpStorm

Tags:

php

phpstorm

Let us suppose we have these 2 methods:

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";
   }
}

So what I want to achieve is to put a breakpoint in PhpStorm into function wear but I want to get fired only when $superhero variable has the value CHUCK_NORRIS how I can do that. Imagine that the function superFunction is getting called over a zillion times and pressing F9 all over the time is kind of counter productive.

like image 683
Dimitrios Desyllas Avatar asked Mar 08 '18 13:03

Dimitrios Desyllas


1 Answers

Put the breakpoint in PhpStorm as usual then right-click on the red disc that marks the breakpoint in the editor's gutter. In the popup window that opens enter the condition when you want your breakpoint to stop the execution of the script. Any condition that is valid in the code where you put the breakpoint can be input here.

For example, enter $superhero===CHUCK_NORRIS.

Press the "Done" button and you're good to go. Debug the script as usual. The debugger evaluates the condition everytime the breakpoint is hit but it stops the script only when the condition is evaluated to true.

like image 169
axiac Avatar answered Sep 22 '22 07:09

axiac