DebugHelper
in package
Development debugging utility for readable array output and call stack analysis
DebugHelper provides essential debugging tools that automatically adapt output formatting based on execution environment (CLI vs web). Includes array dumping with proper formatting and call stack analysis for tracing execution flow.
Environment Adaptation
- CLI: Plain text output with ASCII separators
- Web: HTML output with inline CSS styling and XSS protection
Core Features
- Array dumping with nested structure support
- Call stack analysis with configurable depth
- Automatic environment detection and formatting
- Safe handling of mixed data types and null values
Security Warning
Development only - Never use in production. Can expose sensitive data and internal application structure.
Tags
Table of Contents
Methods
- dump() : void
- Output associative array contents in environment-appropriate readable format
- getCallerInfo() : string
- Analyze debug backtrace to identify function call relationships and source locations
Methods
dump()
Output associative array contents in environment-appropriate readable format
public
static dump(array<string|int, mixed> $result) : void
Automatically detects CLI vs web environment and formats output accordingly. CLI uses plain text with ASCII separators, web uses HTML with inline styling.
Output Formats
- CLI: Plain text headers, uppercase keys, raw print_r() for arrays
- Web: HTML styling, monospace font, color coding, XSS protection
Data Handling
- Nested arrays with proper indentation
- Mixed data types (scalars, arrays, null values)
- Safe null value representation
- Large array support
Parameters
- $result : array<string|int, mixed>
-
Associative array containing data to display for debugging.
Tags
Return values
void —Outputs formatted content directly, no return value.
getCallerInfo()
Analyze debug backtrace to identify function call relationships and source locations
public
static getCallerInfo([int $depth = 2 ][, bool $fullStack = false ]) : string
Provides two modes: single caller analysis (default) for focused debugging, and full stack analysis for complete execution path tracing.
Modes
- Single Caller: Returns "caller() called callee() in file.php on line 123"
- Full Stack: Returns numbered list of complete call chain with error_log() output
Depth Parameter
Controls which stack frame to analyze:
- depth=1: Immediate caller of getCallerInfo()
- depth=2: Default, typical caller-callee relationship
- depth>2: Higher up the call stack
Parameters
- $depth : int = 2
-
Stack frame depth to analyze. Default 2 for typical caller-callee relationship.
- $fullStack : bool = false
-
When true, returns complete call stack and logs to error_log().
Tags
Return values
string —Human-readable caller information or complete call stack.