Login / Status
developer.Resource
Home . Documentation . Document Library . Core Documentation
Sponsors
hosted by punkt.deTYPO3 and Open Source Magazine

1.4. Coding: best practices

This section documents best practices when developing for TYPO3.

Accessing the database

The TYPO3 database should be always accessed through the use of $GLOBALS['TYPO3_DB']. This is the instance of t3lib_db class from t3lib/class.t3lib_db.php.

The same rule applies for accessing non-TYPO3 databases: they should be accessed by using a different instance of the same class. Failing this condition may corrupt TYPO3 database or prevent access to TYPO3 database for the rest of the script.

Singletons

TYPO3 supports singleton pattern for classes. Singletons are instantiated only once per HTTP request regardless of the number of calls to the t3lib_div::makeInstance(). To use singleton pattern class must implement t3lib_Singleton interface:

require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
class tx_myext_mySingletonClass implements t3lib_Singleton {
...
}

This interface has no methods to implement.