Como depurar o seu código

From Joomla! Documentation

This page is a translated version of the page How to debug your code and the translation is 44% complete.
Other languages:
English • ‎Nederlands • ‎español • ‎français • ‎português • ‎中文(台灣)‎

A Maneira Fácil 1 (eco)

The simplest way to see what is going on inside your code is to temporarily add echo statements for variables to show their values on the screen. For example, say you want to know what the value of some variables are when $i is "5". You could use code like this:

for ( $i = 0; $i < 10; $i++ ) {
	if ( $i == 5 ) {
		echo '$i=' . $i; 
                // other echo statements 

This works for simple situations. However, if you are planning on doing a lot of Joomla! development, it is worth the effort to install and learn an integrated development environment (IDE) that includes a real PHP debugger.

A Maneira Fácil 2 (Mensagem do Joomla)

Your code won't always display simple echo statements. In that case you can try this alternative, still easy way:

JFactory::getApplication()->enqueueMessage('Some debug string(s)');

You can choose different message types which corresponds to grouping with different styles (colors mainly).

Registo do Joomla

Joomla allows you to log messages to a log file, and optionally also display these on the web page (in the same way as enqueueMessage above) and on the Joomla Debug Console (described below).

To log a message in the log file:

JLog::add('my error message', JLog::ERROR);

To log a message and also display it on the screen:

JLog::add('my error message', JLog::ERROR, 'jerror');

The logging to the log file and to the Debug Console is controlled via the settings of the System – Debug plugin. To understand how this works, and the relevant settings of the System-Debug plugin, read the Joomla documentation page on Using JLog.

Utilizar um IDE

Check this 3 minutes video that shows how you can debug your code with a Browser and an IDE

Many Joomla! developers use the Eclipse IDE. This is free and includes a debugger. Instructions for installing it are available at Setting up your workstation for Joomla! development, or you can watch this video on setting up Eclipse and Xdebug:

Utilizar um editor "Avançado" de PHP

Another option is the PHP Expert editor with an installed extension for debugging. Add the following lines to the php.ini file:


It is best to set profiler_enable to "off". Then you need to set options in the Run/Options menu to use HTTP-server and the directory in which your script is located. If all options are correct, you may run your script in debug mode by clicking on the Debug button (F8)


An often handy extension that can be found in the JED is the J!Dump extension that will allow you to dump variable, stack traces, and system information into a popup window at run time. This extension works like the PHP command `var_dump` but formats the output in a much more readable fashion.

Consola de Depuração do Joomla

The Debug Console can be enabled from the Joomla! Global Configuration, System tab, by setting the Debug System option to Yes. Once enabled the output of the debug plugin will be displayed at the bottom of each page. The JDebug Plugin output

Setting this Debug System option also sets the global variable JDEBUG to true, so that you can control whether to log messages by testing this variable:

    //whatever debugging code you want to run, eg
    JLog::add('my debug message', JLog::DEBUG, 'my-debug-category');

This plugin provides important information that can assist in debugging and improving the performance of your component.

Informação da Sessão

This section displays state variables which are stored in the Session data to enable them to be 'remembered' across HTTP requests. Examples include variables defining the current search filters the user has defined, the pagination point in a list of records, etc.


Informação do Perfil

The Profile Information tab from the debug plugin provides information about the time and memory taken to render the page based on each of the application events. This can help to identify areas outside of network speed that are contributing to long page load times high server memory usage.

Perfil de JDEBUG

Consultas da Base de Dados

One of the most useful tabs is the Database Queries tab. This will provide a log of all queries that have been executed while loading the page and identify both the time taken to execute the query and whether duplicate queries have occurred. This is particularly useful when debugging performance problems on larger components as duplicate queries are often a contributing factor.


Komodo IDE

Debugging Joomla with Komodo IDE