DEV Community

Cover image for Using dd (dump and die) function in PHP

Using dd (dump and die) function in PHP

Saymon Tavares on September 15, 2021

One of the most common ways to debug an error in PHP ecosystem is to dump the variable on the screen, and figure out what is going wrong with it. ...
Collapse
 
he110 profile image
Elijah Zobenko • Edited

A very handy thing!
I would suggest two things:

  • You can extend the argument list to make it support an unlimited amount of data passed
// three dots before $additional are important
function dd($data, ...$additional): void
{
    echo '<pre>';
    var_dump($data, $additional);
    echo '</pre>';
    die;
}

dd('test', ['another' => 'test'], null, false, 123);
Enter fullscreen mode Exit fullscreen mode
  • There is an amazing library called var-dumper. It makes the similar thing, but supports cli mode