Dealing with *DEPTH TOO GREAT* in Kint

Posted by patrick on Wed, 12/13/2017 - 08:58

If you use Devel's dpm() with Kint for debugging in Drupal 8, chances are you already encountered the message *DEPTH TOO GREAT* when clicking through a deeply nested object.

There is a reason for that: Performance. Always rendering all levels of a deeply nested object might result in either your server or your browser to run out of resources and fail. That's why there is a maximum number of levels to show. It's usually at 7 levels.

If you need to inspect something that is nested further below, the best thing to do is to limit the dpm() to a more explicit part of the nested variable. But sometimes you can't or don't want to do that. In those cases, you can increase the maximum levels by placing

\Kint::$maxLevels = 8;

somewhere above your dpm() call. $maxLevels is of course the maximum number of levels you want to see. If you know what you're doing, you could even use

\Kint::$maxLevels = 0;

to remove the limit entirely. Use at your own risk.

Drupal 8/9
Devel Kint dpm