1

I have several questions regarding this issue:

  1. On other parts of Joomla, I can use var_dump to output variable to debug, but in some events like onUserAfterSave, var_dump won't work. I kind of know what's going on, but can someone explain to me the details of why it won't work? Is it related to "output buffer"? If the result of var_dump doesn't show on screen, where does it go?

  2. Since var_dump doesn't work, I am using another way to see the variables in the onUserAfterSave function:

    JFactory::getApplication()->enqueueMessage(json_encode($something))

This proves to be working in most situations, the JSON string of $something will show on screen and I can copy it to some online json decoder to have a better view of the variable, as most of the variables I am trying to see are objects. But json_encode can't get the object's private properties and methods. Is there a better way (for example using Joomla's own debug system) to get a tree view of the variables? I read some documentation of JDebug, but couldn't figure out how to easily get a tree view of object variables.

1

If you're doing a lot of Joomla development then using a symbolic debugger within an IDE is indispensible in my opinion. It takes a bit of effort setting it up, but repays the effort multiple times over.

There are some guidelines at https://docs.joomla.org/How_to_debug_your_code about how to set it up, and you can hopefully adapt what's there to your own preferred IDE.

I'm not sure exactly the situation regarding onUserAfterSave, but in general the reason that var_dump() output disappears is that Joomla ends up doing a redirect to another URL.

So for example, if your code is handling an HTTP POST, and you call var_dump() then that output will go in the response to the HTTP POST. If however Joomla ends up sending a redirect as the response then the browser will immediately make a new HTTP request to the redirect URL, and whatever you tried to put into the POST response will not appear.

If you call enqueueMessage() then Joomla stores that message in the session, and retrieves and displays it when the new redirected HTTP request is received.

2
  • Mostly I use atom, don't think that is a legit IDE. I can't find a free IDE capable of doing Joomla debug, could you please recommend one? Thanks.
    – shenkwen
    Sep 11 '20 at 1:09
  • @shenkwen I use Eclipse (which is free). On the page I quote above you can find a video which I did to show how to set eclipse up for debugging Joomla. It's maybe a little out of date. On the video youtube page there's a link to a troubleshooting guide I did associated with the video. Sep 12 '20 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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