Debug Helper
The Debug Helpers provide a set of powerful functions to inspect variables, arrays, objects, and JSON data with a beautiful UI in LavaLust. These tools are invaluable for development and debugging purposes.
Note
These helpers are globally available and do not require any additional loading. They automatically format output with syntax highlighting, collapsible structures, and execution context information.
Function Summary
Function |
Description |
|---|---|
|
Dumps one or more variables and stops execution (Dump and Die). |
|
Dumps one or more variables without stopping execution. |
|
Displays an array or object as an HTML table with support for both flat and matrix data. |
|
Pretty-prints JSON data or automatically decodes and formats JSON strings. |
Available Functions
- dd(...$vars)
Dumps one or more variables with a beautiful UI and stops subsequent script execution.
- Parameters:
$vars (
mixed) – One or more variables to dump (variable arguments).
- Returns:
void — Terminates script execution after output.
Example:
<?php $user = ['name' => 'Ronald', 'role' => 'admin']; dd($user, $_SERVER['REQUEST_METHOD']);
- dump(...$vars)
Dumps one or more variables without stopping script execution.
- Parameters:
$vars (
mixed) – One or more variables to dump (variable arguments).
- Returns:
void
Example:
<?php $data = ['foo' => 'bar', 'baz' => 123]; dump($data); echo "Script continues...";
- ddt($data, $label = '')
Displays an array or object as an HTML table. Automatically detects whether the data is a flat key-value pair or a matrix (array of rows).
- Parameters:
$data (
array|object) – The data to display as a table.$label (
string) – Optional label to display in the table header.
- Returns:
void
Example:
<?php // Display database results as a table $users = $db->get('users'); ddt($users, 'Users List'); // Display a single record $user = ['id' => 1, 'name' => 'Ronald', 'email' => 'ronald@example.com']; ddt($user, 'User Details');
- ddj($data)
Pretty-prints JSON data. If a JSON string is provided, it will be automatically decoded and re-encoded with proper formatting.
- Parameters:
$data (
mixed) – A JSON string or any PHP value that can be encoded to JSON.
- Returns:
void
Example:
<?php // Display decoded API response $response = '{"status":"success","data":{"id":1,"name":"LavaLust"}}'; ddj($response); // Display PHP array as formatted JSON $config = ['debug' => true, 'timezone' => 'UTC']; ddj($config);
Output Features
All debug functions provide a consistent, visually appealing output with the following features:
Syntax Highlighting: Different colors for different data types (strings, numbers, booleans, null, etc.)
Context Information: Shows the file name and line number where the dump was called
Collapsible Structures: Arrays and objects can be collapsed/expanded for easier navigation
Type Annotations: Clearly indicates the data type of each value
Length Indicators: Shows string lengths and array/object counts
Visibility Markers: For object properties, shows public, protected, or private visibility
Responsive Design: Works well on different screen sizes with scrollable containers
Note
For best visual results, ensure your development environment has access to modern browsers that support the built-in CSS styling. The output is intentionally formatted for readability during development and should not be used in production environments.
Additional Notes
The
dd()function terminates script execution immediately after displaying output, making it useful for early debugging and code inspection.The
dump()function allows you to continue script execution, useful for logging multiple points in your code.Nested arrays and objects are automatically formatted with indentation and collapsible sections for better readability.
The
ddt()function intelligently detects whether you’re displaying a single record or multiple records and formats accordingly.Maximum recursion depth is limited to 6 levels to prevent performance issues with deeply nested structures.
All output is HTML-escaped to prevent XSS vulnerabilities when dumping user-supplied data.