sebastian/exporter
Exports PHP variables into readable, stable string representations for visualization and debugging. Handles scalars, arrays, objects, resources, binary strings, and recursive references, producing clear output useful in test failures and developer tooling.
var_dump(), dd(), and print_r() for complex data structures like Eloquent models, nested API responses, or custom collections.php artisan tinker). The deterministic output format is ideal for test failures, CI/CD logs, and diagnostics.sebastian/exporter) with no Laravel-specific setup. Works alongside existing tools like Laravel Debugbar or Tinker.dd($variable) with:
$exporter = new \SebastianBergmann\Exporter\Exporter();
echo $exporter->export($variable);
shortenedExport() for large datasets (e.g., API responses) to avoid performance hits.assertEquals() failures with structured exports).| Risk Area | Mitigation Strategy |
|---|---|
| PHP Version Support | Ensure Laravel’s PHP version (e.g., 8.1–8.2) aligns with package support (dropped PHP 8.3 in v8.0). |
| Performance Overhead | Use shortenedExport() for large arrays/collections; benchmark in CI/CD. |
| Circular Reference Handling | Test with Eloquent models and custom recursive structures. |
| Binary/String Output | Verify handling of encrypted data or file uploads (e.g., Symfony\Component\HttpFoundation\File\UploadedFile). |
| Deprecation Warnings | Monitor PHP 8.5+ warnings (e.g., NAN/INF coercion) and update as needed. |
var_dump()/dd() in the team’s workflow? (e.g., Tinker, Debugbar, logs).DebugHelper trait)?shortenedExport()?phpunit --debug.)protected $hidden in models)?exporter instead of raw var_dump?require?dd()/var_dump() in Tinker, Debugbar, and custom Artisan commands.Assert extension).symfony/debug, laravel/ide-helper).| Phase | Action | Tools/Examples |
|---|---|---|
| Evaluation | Test in a staging environment with critical data structures (e.g., Eloquent models, API responses). | composer require --dev sebastian/exporter + manual dd() replacements. |
| Pilot | Replace dd() in high-debugging areas (e.g., API controllers, test files). |
Custom DebugHelper trait to standardize usage. |
| CI/CD Integration | Update PHPUnit to use exporter for failure output. |
Configure phpunit.xml to use a custom listener. |
| Team Adoption | Enforce via linting (e.g., PHPStan rules) or IDE templates. | VSCode snippets: exporter → $exporter->export($variable). |
| Monitoring | Track CI/CD log cleanliness and performance impact. | Compare before/after phpunit --debug runs. |
User->posts->comments->user).Illuminate\Support\Collection handling.UploadedFile).var_dump() in phpunit.xml or test classes with exporter for cleaner failures.exporter for variable inspection.dd()/var_dump() usage (deprecation warning).app/Exceptions/Handler.php for structured error logs).NAN/INF warnings).^8.0) to avoid breaking changes.Exporter for Laravel-specific types (e.g., Carbon, Collection).export() vs. shortenedExport().// For large API responses:
$exporter->shortenedExport($response->getData());
E_WARNING noise).shortenedExport() or limit array depth (v6.1.0+ feature).var_dump()/print_r() for critical paths (e.g., API responses).| Scenario | Impact | Mitigation |
|---|---|---|
| Unsupported PHP Version | Breaks CI/CD or local dev. | Pin to a compatible minor version. |
| Circular Reference Stack Overflow | Crash in debug output. | Test with Eloquent models; use shortenedExport(). |
| Binary Data Corruption | Unreadable output. | Verify with encrypted payloads. |
| CI/CD Log Explosion | Slower pipelines. | Limit export size in tests. |
| Deprecation Warnings | PHP 8.5+ noise. | Monitor updates; suppress if needed. |
dd($var) with:
app('exporter')->export($var);
shortenedExport() for large objects.E_WARNING noise.
How can I help you explore Laravel packages today?