Primordyx Framework Documentation

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
since
1.0.0
example

Basic Usage

// Debug array data
DebugHelper::dump(['key' => 'value', 'nested' => ['data' => 123]]);

// Trace function calls
$caller = DebugHelper::getCallerInfo();
error_log("Called by: $caller");

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
example

CLI Output

DebugHelper::dump(['status' => 'ok', 'data' => ['count' => 5]]);
// === Debug Dump ===
// STATUS:
// ok
// DATA:
// Array( [count] => 5 )
// === END ===
example

Web Output

DebugHelper::dump(['users' => [1, 2, 3], 'meta' => null]);
// Styled HTML container with monospace font and proper formatting
example

Development Workflow

if (defined('DEBUG_MODE') && DEBUG_MODE) {
    DebugHelper::dump(['request' => $_POST, 'session' => $_SESSION]);
}
see
php_sapi_name()

Used for environment detection

see
print_r()

Used for CLI array formatting

see
htmlspecialchars()

Used for web XSS protection

since
1.0.0
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
example

Single Caller

function authenticate($user) {
    $caller = DebugHelper::getCallerInfo();
    error_log("Auth called by: $caller");
    // Logs: "userLogin() called authenticate() in login.php on line 15"
}
example

Full Stack Analysis

function deepFunction() {
    $trace = DebugHelper::getCallerInfo(2, true);
    file_put_contents('trace.log', $trace);
    // Outputs complete execution path with numbered stack frames
}
see
debug_backtrace()

PHP function used internally

since
1.0.0
Return values
string

Human-readable caller information or complete call stack.


        
On this page

Search results