• Posted by marcan
  • Posted on 12/10/2007

icms_debug functions

A few days ago, I added 2 small functions that I have been using for years in our own XOOPS distribution and that I found very useful. They are 2 simple functions that are easily outputting some debug information.

I know that there are some PHP debugger one can use to more efficiently debug its code, but I honestly never got any to work. So I do like many of us do and when something goes wrong, I need to add some echo here and there to see what is going on. These echo lines are not very aesthetic and they are often hard to remove if you have put many in different files…

[more]

So this is why I needed to use some easy-to-use debugging function.

/**
* Output a line of debug
*
* @param string $msg text to be outputed as a debug line
* @param bool $exit if TRUE the script will end
*/
function icms_debug($msg, $exit=false)

/**
* Output a dump of a variable
*
* @param string $var variable which will be dumped
*/
function icms_debug_vardump($var)

These 2 functions can be used very early in the boot sequence of ImpressCMS (early in include/common.php).

These 2 functions would output a line of text or a dump of a vaiable, both in bold red, easily identifiable on the site.

For example, this line of code :

icms_debug(’hello world!’) ;

would output this :

debug :: Hello world !

As for the second one, this line of code :

icms_debug_vardump($im_multilanguageConfig);

would output this :

debug :: array (
‘ml_enable’ => 1,
‘ml_tags’ => ‘en,fr’,
‘ml_names’ => ‘english,french’,
‘ml_captions’ => ‘English,Français’,
)

And when you are done outputting debug lines and when you have finally found the bug and fix it, a simple search for the string “im_debug” in your editor and you can remove all those debug lines.

The comments are owned by the poster. We aren't responsible for their content.