Laravel dd function limitations

Prior to version 5.0 laravel's dd() function looked as follows:

function dd()
{
    array_map(function($x) { var_dump($x); }, func_get_args()); die;
}

Since 5.0 it looks like this:

function dd()
{
    array_map(function ($x) {
        (new Dumper)->dump($x);
    }, func_get_args());

    die(1);
}

The Dumper is using symfony's VarCloner which is extending the AbstractCloner. This class has a $maxItems attribute set to 2500. See: https://github.com/symfony/var-dumper/blob/master/Cloner/AbstractCloner.php#L125

You have 17 items per array. Multiply it by 147 and you get 2499. That's why your array at key 147 is truncated after it's first item.

If you'd like to increase that you'd need to override laravel's Dumper class (https://github.com/laravel/framework/blob/5.2/src/Illuminate/Support/Debug/Dumper.php):

public function dump($value)
{
    if (class_exists(CliDumper::class)) {
        $dumper = 'cli' === PHP_SAPI ? new CliDumper : new HtmlDumper;

        $cloner = new VarCloner();
        $cloner->setMaxItems(5000);
        $dumper->dump($cloner->cloneVar($value));
    } else {
        var_dump($value);
    }
}

My suggestion is you add a handler in the VarDumper component.

In your AppServiceProvider.php:

(before class declaration)

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

(inside boot() method)

VarDumper::setHandler(function ($var) {
    $cloner = new VarCloner();
    $cloner->setMaxItems(-1); // Specifying -1 removes the limit
    $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();

    $dumper->dump($cloner->cloneVar($var));
});

According to Symfony's VarDumper component documentation:

setMaxItems() Configures the maximum number of items that will be cloned past the minimum nesting depth. Items are counted using a breadth-first algorithm so that lower level items have higher priority than deeply nested items. Specifying -1 removes the limit.

And in the documentation you can see other methods for customizing the Cloners, Dumpers and Casters components.


My suggestions for you is to create a custom helpers file in bootstrap folder

1) follows the following answer to create a custom helper function for your Laravel application, if it is too complicated, you can skip the following step, use my function in step 2 as any normal function and simply call it >> https://stackoverflow.com/a/28290359/10539212

2) I would like to give some credits to this guy, I follow his guide to create my own ddd function >> https://tighten.co/blog/a-better-dd-for-your-tdd

use Illuminate\Support\Debug\HtmlDumper;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;

function ddd()
{
    $args = func_get_args();
    $defaultStringLength = -1;
    $defaultItemNumber = -1;
    $defaultDepth = -1;

    foreach ($args as $variable) {
        $dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();

        $cloner = new VarCloner();
        $cloner->setMaxString($defaultStringLength);
        $cloner->setMaxItems($defaultItemNumber);

        $dumper->dump($cloner->cloneVar($variable)->withMaxDepth($defaultDepth));
    }

    die(1);
}

-1 = no limit (easy to customize in this way)

So, now when you use this ddd function, you can get the complete output of normal dd function. I think this approach is better than overwriting any existing function. But be careful, since now variables with any number of depth will be displayed completely, you may experience longer loading time. Hope it helps.