0

I am learning advanced theming for which I am using Devel Module kpr() and dsm() functions to print the arrays on the page for finding variables. So I want to know, What is the main difference between kpr() and dsm() functions? And which one is the best for which condition.

1 Answer 1

2

In Devel there are various formatters you can use to dump variables. But the main difference of dsm() is, that it uses drupal_set_message(), which displays the output in the message array via a session, so that the information is preserved between different requests of the same user. This is helpful for debugging code, which doesn't result in a html page to display a normal var dump, for example a form submit. The disadvantage is, that dsm() sometimes produces the output asynchron, not when you expect it, which can lead to false conclusions.

2
  • But sometimes one of the function is not working. I have installed devel on my fresh installation kpr() is working while the dsm isn't working. Commented Sep 28, 2017 at 8:56
  • 1
    As I've described this depends on when the code runs you want to debug. Most times both work, but there are cases only one of them works. Or none of them, then you need an IDE and Xdebug.
    – 4uk4
    Commented Sep 28, 2017 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.