All page names need to be in English.
en da  de  fr  it  ja  km  nl  ru  zh

Extension Development, Debugging

From TYPO3Wiki
Jump to: navigation, search

<< Back to Extension Development page


notice - Draft

Change the {{draft}} marker to {{review}} when you need a reviewer for text and TypoScript. info

Tipps on debugging

Debug TYPO3

See also the Extension Developers Guide

  • In typo3conf/LocalConfiguration.php, set [FE][debug] = 1 and [SYS][devIPmask] to e.g. "192.*,169.*,". Then use the extended debug() function of the Extension cc_debug. On your TYPO3 site you will see a bomb ([[1]]) in the upper right corner if there is debug output by the currently running PHP script.
 // show the variable together with the line number and file name
 debug($variable, 'Variable name/description', __LINE__, __FILE__);

Alternatively you can use the extension beko_debugster or fh_debug. These will also work if there are HTML or JavaScript errors on a page.

 // display the variable
 debugster($variable, 'Variable name/description');

 // show the stack trace of the current function
 $tmp = t3lib_div::debug_trail();
 debug($tmp, 'stack trace in className::methodName', __LINE__, __FILE__);
 // Replace 'className' with the name of the class and 'methodName' with the name of the method from where you call <tt>debug()</tt>.

 // If you want to add devLog functionality to your applications, simply write lines like this:
 if (TYPO3_DLOG) {
   \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('some message', 'extension_key');
   // (…used to be »t3lib_div::devLog(), you may still see this in older examples)
   // …if you want debug data use this
   \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('some message', 'extension_key', 0, $dataArray);

The devlog-function itself provides only an interface for logging but no implementation to store the logs. So you need an extension save the log message to a desired place.
The devlog extension provides development logging/debugging functionality and stores the logs into a MySQL table by default. The
rlmp_filedevlog logs messages into a text file (by default to debug.log of your web server home directory, e.g. at /var/www/html/ - do not forget to allow write access for the httpd user).

You have to activate the devlog functionality on your system as well, by adding the following line to typo3conf/LocalConfiguration.php:

 $TYPO3_CONF_VARS['SYS']['enable_DLOG'] = true;


You can write to the (system) error log using:

 error_log('text', 0);
 error_log('postition A: $content='.$content, 3, '/usr/local/htdocs/typo3/error_log');

and view the entries of the log file. (Linux: /var/log/messages, /var/log/apache2/error_log or /var/log/httpd/error_log).

You can modify the error_log = syslog settings in /etc/php.ini.

If you supply a third parameter to error_log(), it will write that log entry to this file only.

To show the contents of arrays, you use foreach loops:

 foreach ($menuItems as $key => $menuItem) {
 	if (is_array($menuItem)) {
 		error_log ('-- tx_commerce_cm1 menuItem['.$key.'] --', 0);
 		foreach ($menuItem as $k1=>$v1) {
 			error_log ('['.$k1.']='.$v1,0);
 	} else {
 		error_log ('-- tx_commerce_cm1 menuItem['.$key.'] = '.$menuItem, 0);

Or use these lines with var_dump():

 $debugOut = ob_get_contents();
 error_log ('$myComplexArray = '.$debugOut);

How to debug SQL

 $GLOBALS['TYPO3_DB']->store_lastBuiltQuery = true;
 $GLOBALS['TYPO3_DB']->exec_UPDATEquery( 'xxx', 'yyy', 'zzz');
 t3lib_div::devLog('[write message in english here]'.$GLOBALS['TYPO3_DB']->debug_lastBuiltQuery , 'extension key');

Use debug_mysql_db to debug SQL queries, measure query execution time and hide unnecessary PHP warning messages.

How to debug TypoScript

See TypoScript Reference, section stdWrap.

At the end of the table you will see three stdWrap options which enable various debug modes:

  • debug boolean

Passes output through htmlspecialchars(). Useful for debugging which value stdWrap actually ends up with while you're constructing a website with TypoScript.

  • debugFunc boolean

Prints the content using the debug() function. Set to value "2" (well, it's not *quite* a boolean;)) the content will be printed in a table - looks nicer. Example:

 marks.MENU_TITLE.field = title
 marks.MENU_TITLE.stdWrap.debugFunc = 2
 marks.MENU_TITLE.stdWrap.wrap = title at position 1 |

  • debugData boolean

Prints the current data-array, $cObj->data, directly to browser. This is where ".field" gets its data from.

A trick that's extremely useful while developing is simply build an extension template (+ext) for the specific page you want to debug; so that you can manipulate your TypoScript code as you want without affecting other pages. Once you've finished debugging, delete the extension template.

  • debugItemConf boolean

Outputs the configuration arrays for each menu item, using the debug()-function. Useful to debug optionSplit things and such. Applies to GMENU, TMENU, IMGMENU.

An example:

 temp.L2menuItems = HMENU
 temp.L2menuItems.entryLevel = 1
 temp.L2menuItems.1 = TMENU
 temp.L2menuItems.1.debugItemConf = 1