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
| Subject | Key difference |
|---|---|
| Step debugging vs profiling | Step debugging pauses individual statements; profiling records aggregate runtime cost. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Enabling the debugger for every production request | Use controlled triggers and disable development modes in production. |
| Skipping the prerequisite of this specific workflow | Install or configure the named tool and confirm the example can actually run. |
| Ignoring edge conditions | Conditional 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.