Content · Web Development · PHP

Debugging with Xdebug Breakpoints

Line and conditional breakpoints pause PHP before selected statements, exposing variables and the execution stack.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

Line and conditional breakpoints pause PHP before selected statements, exposing variables and the execution stack.

What It Does


Place a breakpoint inside the loop and inspect $line and $sum. Trigger a step-debug request.

Requirements and Compatibility


Use a supported PHP runtime and install any third-party tool or extension explicitly shown in the examples. Commands should be run from the project root unless stated otherwise.

Syntax, Inputs and Results


The examples separate configuration, the smallest working operation and a realistic follow-up task. Adapt file paths and dependency versions to your own project.

Example 1: Basic Use


Place a breakpoint inside the loop and inspect $line and $sum.

<?php
function total(array $lines): int {
    $sum = 0;
    foreach ($lines as $line) { $sum += $line; }
    return $sum;
}
echo total([10,20,30]);

Example 2: Another Case


Trigger a step-debug request.

xdebug.mode=debug
xdebug.start_with_request=trigger
xdebug.client_port=9003
xdebug.log_level=0

Practical Example


Only stop on the expensive branch.

Breakpoint expression: $line > 15
Watch expression: $sum
Step over: advance to next iteration

For production, apply the compatibility and edge-case limits described below.

Important Behavior and Edge Cases


Conditional breakpoints avoid stopping on every iteration when investigating a rare input.

Comparison with Related Functions and Tools


SubjectKey difference
Step debugging vs profilingStep debugging pauses individual statements; profiling records aggregate runtime cost.

Common Beginner Mistakes


MistakeCorrect approach
Enabling the debugger for every production requestUse controlled triggers and disable development modes in production.
Skipping the prerequisite of this specific workflowInstall or configure the named tool and confirm the example can actually run.
Ignoring edge conditionsConditional breakpoints avoid stopping on every iteration when investigating a rare input.

Key Takeaways


  • Line and conditional breakpoints pause PHP before selected statements, exposing variables and the execution stack.
  • Conditional breakpoints avoid stopping on every iteration when investigating a rare input.
  • Keep application configuration, source code and validation tests under version control.

Use these examples as a starting point, then validate the result with the actual PHP build, dependencies and inputs used by your application.

Share this resourceSend this page to someone who may find it useful.