zendframework/zend-debug
zend-debug provides debugging utilities for Zend Framework apps, including variable dumping, debug messages, and helpers to inspect execution during development. Useful for troubleshooting and profiling in legacy ZF-based projects.
Installation Add the package via Composer in your Laravel project:
composer require zendframework/zend-debug
Since this is an archived package, ensure compatibility with your PHP version (tested up to PHP 7.2).
Basic Setup
Register the Zend\Debug\Debug class in your Laravel service provider (e.g., AppServiceProvider):
use Zend\Debug\Debug;
public function boot()
{
Debug::enable();
}
First Use Case
Use Debug::dump() or Debug::dumpVar() in a route or controller to inspect variables:
use Zend\Debug\Debug;
Route::get('/debug', function () {
$data = ['user' => 'John', 'status' => 'active'];
Debug::dump($data); // Outputs formatted variable dump
return 'Check your debug output';
});
Debugging Variables
Replace dd() or var_dump() with Debug::dump() for consistent, formatted output:
Debug::dump($user, 'User Data'); // Labels the dump for clarity
Conditional Debugging Enable/disable debugging dynamically (e.g., via environment):
if (app()->environment('local')) {
Debug::enable();
}
Integration with Laravel Logs Log debug output to Laravel’s log system for non-browser environments:
Debug::dump($query, 'SQL Query');
Log::debug(Debug::getDump());
Custom Exceptions
Use Debug::dump() in exception handlers (App\Exceptions\Handler) for stack traces:
public function render($request, Throwable $exception)
{
Debug::dump($exception, 'Exception Details');
return parent::render($request, $exception);
}
CLI Debugging Pipe debug output to a file in Artisan commands:
Debug::dump($result);
file_put_contents(storage_path('logs/debug.txt'), Debug::getDump());
Debug::dump() in middleware to log requests/responses:
public function handle($request, Closure $next)
{
$response = $next($request);
Debug::dump($request->all(), 'Request Data');
Debug::dump($response->getContent(), 'Response Data');
return $response;
}
illuminate.query):
public function handle()
{
Debug::dump(event('illuminate.query')->sql);
}
Debug::dump() in Blade files (disable in production):
@if(app()->environment('local'))
{{ Debug::dump($post) }}
@endif
Performance Overhead
Debug::dump() halts execution and outputs raw data (unlike Laravel’s dd()).if (!app()->environment('local')) {
return;
}
Debug::dump($data);
Output Buffering Conflicts
ob_start() isn’t interfering or flush buffers manually:
if (ob_get_level()) {
ob_end_flush();
}
Debug::dump($data);
Deprecated Methods
Debug::dumpVar()) may behave differently than expected.Debug::dump() for consistency.No Laravel-Specific Features
Log::debug() or third-party tools like barryvdh/laravel-debugbar.Archived Package Risks
Debug::setDumpFormat() (e.g., JSON, HTML).'debug' => [
'enabled' => env('APP_DEBUG', false),
],
Then check config('debug.enabled') before dumping.file_put_contents(
storage_path('logs/debug-' . now()->format('Y-m-d') . '.log'),
Debug::getDump()
);
Debug::dump() in App\Exceptions\Handler to log full stack traces:
Debug::dump($exception, 'Unhandled Exception');
Custom Dump Handlers
Extend Zend\Debug\Debug to add Laravel-specific features:
class LaravelDebug extends Debug
{
public static function dumpLaravel($data, $label = null)
{
if (app()->bound('log')) {
Log::debug($label ?: 'Data', $data);
}
parent::dump($data, $label);
}
}
Hook into Laravel’s Debugbar
Integrate with barryvdh/laravel-debugbar to avoid duplication:
Debugbar::info('Zend Debug', Debug::getDump());
Environment-Specific Dumps Create a trait for reusable debug logic:
trait Debuggable
{
protected function debug($data, $label = null)
{
if (app()->environment('local')) {
Debug::dump($data, $label);
}
}
}
How can I help you explore Laravel packages today?