No More var_dump - Introducing Symfony VarDumper!

I ran into this thing and it got me away from using my handmade suite - that’s a feat right there. I’m incorporating it into a patch I’m writing for Drupal 8 to improve how the stacks are dumped on the error event when the system is configured into dbug mode. It’d definitely a help there since drupal’s objects are huge and massively recursed.

1 Like

One should always pick a debugging solution that would work without changing the codebase back and forth. Any kind of var_dump should never be available on production. Any method used should always include a production check and disablee the output eg. if (PRODUCTION) dont dump.

Last time I checked it was fully possible run any one of a number of PHP’s debug statements on a production box if you’re foolish enought to do so. How is this any different?

Ironically I had this discussion with my boss eariler today. I give you the same challenge as I gave him - how is this any more destructive or harmful than leaving a print_r(); exit; series in the code?

Answer, it isn’t.

Keeping test code separate from production code is an issue beyond the scope of what this tool addresses.

using print_R() and exit is just as harmful as I have cleaned up the code on production when those debug statements got released on production.

I dont say you shouln’t use them but always do something like this instead:

if (!empty($_GET['we_are_debugging'])) {
   print_R('data');die()
}

with that simple check you can debug on local and production still continues to work.

That being said, your unit tests should catch it before that though

EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.

Then you’re permanently wasting code cycles on the eval of the conditional. And who would ever use a $_GET var to determine debug mode? Talk about rolling out the red carpet to hackers…

Thanks for this !! I’m just switching from kint :slight_smile: +1 for kint too

Also just thought I’ll mention it on this thread that VarDumper works awesome on the console with some good color coding !!

Cheers

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.