This PHP snippet provides a simple, elegant way to debug and display the contents of variables, arrays, and objects in a human-readable format. It highlights the data with custom styling, making it easier to analyze complex structures in your application.
- Array and Object Dumping: Displays arrays and objects with proper indentation and formatting.
- Custom Styling: Includes custom CSS for better visibility of different data types.
- Support for Various Data Types: Supports strings, integers, floats, booleans, null values, arrays, and objects.
- Syntax Highlighting: Color-coded output for better readability.
Requires PHP 5.6+
- Copy the Functions:
Copy the provided
highlight
,dump
, anddd
functions into your PHP project. - Add CSS Styles:
The
dump
function includes internal CSS styles. You can customize these styles to fit your project’s design or remove them if you prefer to use external styles. - Use the Functions:
dump($data)
– Outputs the formatted and highlighted data.dd($data)
– Outputs the formatted data and then stops the script execution.
<?php
$technologiesArray = ['TailwindCSS', 'AlpineJS','Livewire', 'Laravel'];
$courseArray = [
'name' => 'TALL Stack Course',
'price' => 14.99,
'published' => true,
'author' => null,
'technologies' => $technologiesArray
];
class Course
{
public $name = 'TALL Stack Course';
public $price = 14.99;
public $published = true;
public $technologies = ['TailwindCSS', 'AlpineJS', 'Livewire', 'Laravel'];
}
$courseObject = new Course();
dump($courseArray);
dump($courseObject);
This will display the $courseArray
and $courseObject
in a visually appealing format with syntax highlighting.
- Recursively processes arrays and objects, generating a formatted string with HTML elements and appropriate indentations.
- Parameters:
$data
: The data to be highlighted (can be an array, object, or any other type).$tab
: The indentation level for nested structures.
- Outputs the highlighted data wrapped in a
<pre>
HTML tag with custom styling. - Parameters:
$data
: The data to be dumped.
- Dumps the data and immediately halts further script execution.
- Parameters:
$data
: The data to be dumped.
You can adjust the styles in the <style>
tag inside the dump
function to match the visual aesthetics of your project. The colors for strings, numbers, booleans, and other types are customizable.
PHP Debugger is an open-sourced snippet licensed under the MIT License.