Debugging PHP with Java console.
It may seem a strange title for a blog, but we have been looking at a small ‘opportunity’ in converting one of our components to Joomla 3.x.
Two possible means of tracking the cause occurred to us. The first would involve creating a logging routine whereby we could write messages to a log file from the inner PHP routine or alternatively making use of the JLog class.
For those not familiar with the console object, it provides access to the browser's debugging console. The specifics of how it works vary from browser to browser, but there is a de facto set of features that are typically provided. The most frequently-used feature of the console is logging of text and other data. There are four categories of output you can generate, using the
console.error() methods. Each of these results in output that's styled differently in the log, and one can use the filtering controls provided by the browser to only view the kinds of output that are of interest. There is a web page here that describes it in general with a slight emphasis to Mozilla(Firefox).
We have used the second mechanism but even here we met a few ‘opportunities’. Inserting console.log statements around the relevant calls to the inner PHP routine wouldn’t display anything in the Firefox Java console. This was puzzling because we could plainly see other Java errors in the log from other un-associated script errors. So we turned to using the Chrome browser and here we could immediately see the statements we were tracking.
By judicious placement of out console.log statements we soon found the error message which was a call to a $config->getValue statement. We noted reference to the JRegistry object in the error message to the call to the JFactory::getConfig method. We were aware of the deprecation of the getValue method for JRegister so could make our code change.
Changing this to a simple $config->get immediately resolved the problem.
Not all that difficult to resolve but unless one is completely conversant with all of the deprecated features very easy to miss, and even more difficult in our case to track down the cause.
We still do not know why the Firefox Java console wouldn’t display our ‘console.log’ statements. It may be related to out ‘Web Developer plugin’ but we have not investigated this any further. Certainly the Firebug add-on should work with console.log.