yiisoft/var-dumper
Yii VarDumper enhances var_dump()/var_export() with safe handling of recursive references, syntax highlighting, and closure export. Includes handy d(), dump(), and dd() helpers for quick debugging. Configurable depth and highlighting.
yiisoft/var-dumper package remains a lightweight, debug-focused tool with improved features in 1.7.1, such as refined HTML syntax highlighting in EchoHandler. This aligns even better with Laravel’s debugging needs, particularly for development environments requiring structured, visually rich output (e.g., nested objects, API responses).8.0–8.5) ensures compatibility with Laravel’s LTS support (Laravel 10+).yiisoft/yii2).var_dump(), with no Laravel-specific hooks. The HTML syntax highlighting enhancement in EchoHandler improves usability for web-based debugging (e.g., browser DevTools inspection).EchoHandler improvements may require testing for edge cases like malformed data.EchoHandler improvements might introduce subtle rendering issues in non-standard environments (e.g., custom Laravel exception pages). Test with complex objects like Eloquent collections.PHP Version Strategy
^8.0 to future-proof the dependency?HTML Output Use Cases
EchoHandler improvements be critical for debugging web responses (e.g., JSON:API, GraphQL)?render() methods in App\Exceptions\Handler)?Long-Term Maintenance
debugbar or tightenco/ziggy as alternatives to avoid ecosystem lock-in?EchoHandler improvements enhance web debugging workflows (e.g., inspecting dumped data in browser DevTools).EchoHandler bridges the gap between CLI and browser debugging (e.g., dumping API responses in routes/web.php).EchoHandler HTML output in a Laravel web context (e.g., dump a complex Eloquent query result in a route).dump()/dd() for edge cases (e.g., circular references, resources).composer.json to include the new version:
composer require --dev yiisoft/var-dumper:^1.7
var_dump() in web-facing debug statements first (leverage EchoHandler improvements).EchoHandler for web contexts:
if (!function_exists('ydump')) {
function ydump($var, bool $htmlContext = false) {
if ($htmlContext) {
Yisoft\VarDumper\VarDumper::setHandler(new Yisoft\VarDumper\EchoHandler());
}
Yisoft\VarDumper\VarDumper::dump($var);
}
}
ydump($user->load('roles'), htmlContext: true); // HTML-highlighted output
EchoHandler output is opt-in and won’t interfere with CLI tools.barryvdh/laravel-debugbar, but avoid mixing output handlers (e.g., don’t use both EchoHandler and Debugbar for the same dump).xdebug or other extensions, though xdebug may still be recommended for deeper inspection.var_dump() in web routes/controllers to leverage EchoHandler HTML output.bootstrap/app.php).debugbar if HTML output becomes a bottleneck.EchoHandler with edge cases (e.g., non-string data in HTML context).htmlContext flag).htmlContext flag for web-specific dumps.dump() (e.g., no automatic HTML escaping in EchoHandler).EchoHandler by testing with simple arrays first.is_cli() checks or --no-ansi flags for Artisan commands.APP_DEBUG). The EchoHandler adds minimal overhead in development.laravel-debugbar to avoid HTML output in production logs.| Scenario | Impact | Mitigation |
|---|---|---|
| Debug output in prod | Log bloat, security risk | Enforce APP_DEBUG=false in env. |
| HTML rendering errors | Broken output in browser | Test EchoHandler with edge cases; fall back to CLI output. |
| PHP version drop | Package incompatibility | Pin to yiisoft/var-dumper:^1.7 or migrate to Laravel’s tools. |
| Memory leaks | Large dumps in loops | Use Yisoft\VarDumper\VarDumper::setMaxItems() to limit depth. |
EchoHandler and update critical dumps.var_dump() output in browser tools.htmlContext flag and its use cases (e.g., "Use ydump($data, true) in routes for browser inspection").How can I help you explore Laravel packages today?