/ php

VarDumper

I first come acoss VarDumper at: http://www.sitepoint.com/var_dump-introducing-symfony-vardumper/

So I went ahead and added it to my Laravel application.

Works well except for the fact that it truncates the dump.

Notice you can't inspect items 5 and above.

Now to make it dump everything, you'll need to instantiate the Clone and HtmlDumper.

Here's a sample class that sets items and strings limits to unlimited:

<?php
namespace SPG;

use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;


class Dumper {

  public $c;
  public $d;

  function __construct() {
    $this->c = new VarCloner();
    $this->c->setMaxItems(-1);
    $this->c->setMaxString(-1);

    $this->d = new HtmlDumper();
  }

  function dump($var) {
    $this->d->dump($this->c->cloneVar($var));
  }
}

And this is how you will use it:

$dd = new SPG\Dumper();
$dd->dump($myVars);

More information at http://symfony.com/doc/current/components/var_dumper/advanced.html

Final result:

Now you can inspect any items with any depths or levels.

Er...so I have 2 lines instead of just calling the dump() function?

You can wrap them with,

  1. A Facade or,
  2. A helper function
VarDumper
Share this