4

I like to use the dd function to debug. This time when I use it to display a list of appointments, I can't see (no clickable arrow) the data in the attributes and original. I get the brackets [ …19] displayed instead, not sure why.

Collection {#3061 ▼
  #items: array:548 [▼
    0 => Appointment {#821 ▼
      #table: "appointments"
      #fillable: array:16 [ …16]
      #connection: null
      #primaryKey: "id"
      #perPage: 15
      +incrementing: true
      +timestamps: true
      #attributes: array:19 [ …19]
      #original: array:19 [ …19]
      #relations: array:2 [ …2]
      #hidden: []
      #visible: []
      #appends: []
      #guarded: array:1 [ …1]
      #dates: []
      #dateFormat: null
      #casts: []
      #touches: []
      #observables: []
      #with: []
      #morphClass: null
      +exists: true
      +wasRecentlyCreated: false
    }
    1 => Appointment {#822 ▶}
    2 => Appointment {#823 ▶}
    3 => Appointment {#824 ▶}
    4 => Appointment {#825 ▶}
    5 => Appointment {#826 ▶}
    6 => Appointment {#827 ▶}
    7 => Appointment {#828 ▶}

And later in the list, I can't even see inside an appointment (no arrows):

    81 => Appointment {#902 ▶}
    82 => Appointment {#903 ▶}
    83 => Appointment {#904 ▶}
    84 => Appointment {#905 ▶}
    85 => Appointment {#906 …23}
    86 => Appointment {#907 …23}
    87 => Appointment {#908 …23}
    88 => Appointment {#909 …23}
    89 => Appointment {#910 …23}
    90 => Appointment {#911 …23}

But when I use var_dump, my data looks fine :

    array(548) {
      [0]=>
      array(21) {
        ["id"]=>
        int(149)
        ["appointmenttype_id"]=>
        NULL
        ["appointmentlocationtype_id"]=>
        NULL
        ["appointment_start"]=>
        object(Carbon\Carbon)#812 (3) {
          ["date"]=>
          string(26) "2015-12-21 07:00:00.000000"
          ["timezone_type"]=>
          int(3)
          ["timezone"]=>
          string(16) "America/New_York"
        }
        ["appointment_end"]=>
        object(Carbon\Carbon)#811 (3) {
          ["date"]=>
          string(26) "2015-12-21 09:00:00.000000"
          ["timezone_type"]=>
          int(3)
          ["timezone"]=>
          string(16) "America/New_York"
        }

Anyone else experienced that situation?

Ash
  • 3,242
  • 2
  • 23
  • 35
user3489502
  • 3,451
  • 9
  • 38
  • 66

3 Answers3

5

This is a not-so-known caveat of returning too large a list of results. Generally, dd() is meant to be a quick overview of the data you are returning, and handles "drill down" well on smaller groups of data. Once you reach a certain number (I forget the exact one, 500 maybe?), that functionality no longer works.

If you absolutely need to see this data before using it in your code somewhere, use a limit() clause before you get() the results, or use dd($example[0]) to see a single results' details. Hope that helps!

Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
1

Not a bug in dd() just how the underlying Sympony VarDumper is configured.

I believe the line in question is this one which has sets $maxDepth to 20 but I haven't checked this.

Looking at the Laravel Dumper logic there doesn't seem to be anyway to override this from within Laravel.

Mark Davidson
  • 5,503
  • 5
  • 35
  • 54
1

I've found a way to work around this, although not recommended, if you really want the entire object dumped, add the following code snippet to /bootstrap/autoload.php

if (! function_exists('dd')) {
    /**
     * Dump the passed variables and end the script.
     *
     * @param  mixed
     * @return void
     */
    function dd()
    {
        array_map(function ($x) {
            $dumper = 'cli' === PHP_SAPI ? new \Symfony\Component\VarDumper\Dumper\CliDumper() : new \Illuminate\Support\Debug\HtmlDumper();
            $cloner = new \Symfony\Component\VarDumper\Cloner\VarCloner();
            $cloner->setMaxItems(-1);
            $cloner->setMaxString(-1);
            $dumper->dump($cloner->cloneVar($x));
       }, func_get_args());

        die(1);
    }
}

This must be added above the line:

require DIR.'/../vendor/autoload.php';

It overrides the laravel dd function and sets 'setMaxItems' and 'setMaxString' on the Symfony VarCloner object before dumping.

A.R
  • 11
  • 1