Search code examples
debuggingphpstormbreakpoints

PhpStorm debugger breakpoint at variable use


Is it possible to set a "PHP Exception Breakpoint" inside of PhpStorm debugger so that it triggers each time a specific variable is used?

For example I have a $_GET['foo'] in request and want debugger to pause every time the variable $_GET['foo'] is used in code.


Solution

  • Exception breakpoints only trigger when an error has occurred, so the short answer is "no."

    However, you can right-click (or control+click, for Mac) the top folder in your source tree in the project file browser and choose "Find in Path" to locate all instances of $_GET['foo']. Once you know where they all are, create normal breakpoints in the usual way. Then put them into a "group," according to your intentions for those breakpoints:

    1. Create breakpoints everywhere $_GET['foo'] is referenced, using the "Find in Path..." feature of the project file browser to search for them globally (Find the main folder of your project; then Right-click for PC or [Control]+[Click] for Mac to find this option).
    2. Once your breakpoints are set everywhere you find $_GET['foo'], click Run > View Breakpoints to show them in a list.
    3. Select all of the corresponding breakpoints using [Command]+[Click] or [Shift]+[Click] to select multiple entries, if necessary.
    4. Right-click or [Control]+[Click] your group of selected breakpoints in the list (or just an individual breakpoint, if you like) and choose Move to group. If you do not have any groups made up yet, just choose Create group to make a new one.

    In the View Breakpoints screen, you can then enable or disable the entire breakpoint group by checking its box. When that group and its breakpoints are no longer needed, you can delete a group by clicking the [-] minus button.