Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Exporter Laravel Package

sebastian/exporter

Exports PHP variables to readable, deterministic strings for visualization and debugging. Handles scalars, arrays (including recursion), objects, resources, and special float values (NAN/INF). Useful for test output, diffs, and diagnostics.

View on GitHub
Deep Wiki
Context7

Getting Started

Install as a dev dependency:

composer require --dev sebastian/exporter

Begin by replacing var_dump()/dd() calls in tests or CLI debugging with Exporter. Instantiate once (it’s lightweight and stateless beyond config), then use:

use SebastianBergmann\Exporter\Exporter;

$exporter = new Exporter;
dump($exporter->export($someComplexObject));

The README Usage section is the best starting point—skip the changelog and jump straight to the simple types and complex types examples.

Implementation Patterns

  • Test Helper Trait: Create a reusable trait for PHPUnit tests to ensure consistent, readable failure output:
    trait ExportsVariables {
        protected function export($var, bool $compact = false): string {
            static $exporter;
            $exporter ??= new Exporter(null, 50, 100); // configurable limits
            return $compact ? $exporter->shortenedExport($var) : $exporter->export($var);
        }
    }
    
  • Debug Function Wrapper: Extend Laravel’s dump() with cleaner, recursive-safe output:
    function d(...$vars) {
        $exporter = new Exporter;
        foreach ($vars as $var) {
            fwrite(STDERR, $exporter->export($var) . "\n");
        }
        return $vars[0] ?? null;
    }
    
  • Eloquent/Collections Debugging: Safely export Collection or Model instances—even with lazy relationships—without triggeringN+1 queries (thanks to lazy-object skipping since v6.2.0).
  • Assertion Context: In custom PHPUnit assertions, use shortenedExport() to show concise diffs:
    $this->assertSame(
        $expected, 
        $actual, 
        'Expected ' . $exporter->shortenedExport($expected) . ' but got ' . $exporter->shortenedExport($actual)
    );
    
  • Configurable Limits: Preconfigure for test suites (smaller arrays/strings) vs. full debugging (larger limits):
    new Exporter(null, 25, 200); // maxElements = 25, maxString = 200 chars
    

Gotchas and Tips

  • PHP 8.5+ Compatibility: Older versions (≤6.3.1, ≤7.0.0) emit warnings for NAN/INF and casts. Pin to ^7.0.2 or ^6.3.2 if using PHP 8.5+.
  • shortenedExport() Truncation: Aggressively shortens long strings/arrays—fine for assertion summaries, but use export() for full debugging. Watch for truncated nested structures where recursion markers (&0) may be lost.
  • Constructor Signature: In v6.3.0+, the only way to set string length limit is via constructor args (method args deprecated). Order is (int|null $maxElements = null, int $maxString = 100).
  • Resource Safety: Exporting resources (e.g., streams, sockets) is safe for diagnostics—but never in production logs. Avoid exporting unknown resource types: they may hold open handles.
  • IDE Conflicts: If Xdebug’s xdebug.var_display_max_depth overrides dumps, set it to -1 (unlimited) or -2 (respect max depth) for consistency. Exporter ignores Xdebug config, so output remains predictable across environments.
  • Performance: For massive arrays (e.g., large config dumps), shortenedExport() with maxElements=10 is ~5x faster than full export()—ideal for CI failure summaries. Profile with microtime(true) before/after in non-critical paths.
  • Version Stability: The repo shows a 2026 release date—this is a placeholder. Check Packagist for the actual latest stable (currently v7.x). Laravel ≥10.x supports up to PHP 8.2; v7.x of this package drops support for PHP 8.2+, so lock versions carefully if targeting PHP 8.3+ Laravel projects.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport