Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla var_dump equivalent for arrays in a plugin

I have a Joomla plugin that fires after registration. I'm having issues with it but don't know how to debug it properly as the plugin happens only on events.

Up to this point I've been using default Joomla logging:

jimport('joomla.log.log');
JLog::addLogger(array('text_file' => 'myfile.log.php'));

JLog::add('The value is: '.$something);

That's fine but not for arrays. How can I dump the contents of an array to a file (or console) to see what is going on? Currently it will just show "Array".

like image 962
Tom Avatar asked Sep 15 '25 07:09

Tom


2 Answers

What about this:

JLog::add('The value is: '.print_r($something, true));

Second parameter of print_r() set to true means that it returns a string instead of outputting it

like image 86
yefrem Avatar answered Sep 17 '25 01:09

yefrem


For debugging the best solution is to use an IDE that works with XDebug (like Eclipse with PDT or Jet Brain's PhpStorm), but they aren't always practical if you trying to debug are remotely hosted Joomla! website.

In that case one of the best solutions is J!Dump which will let you show all of you data types and even pop open a debug window for you with a data and process tree.

You can find it in the Development section of the Joomla! Extensions Directory (JED)

J!Dump other methods are discussed in the "How to debug your code" on Joomla!'s Doc's website

like image 27
Craig Avatar answered Sep 17 '25 01:09

Craig