Attention

TYPO3 v10 has reached end-of-life as of April 30th 2023 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.

Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v10 here: TYPO3 ELTS.

File Structure

TYPO3 files use the following structure:

  1. Opening PHP tag (including strict_types declaration)

  2. Copyright notice

  3. Namespace

  4. Namespace imports

  5. Class information block in phpDoc format

  6. PHP class

  7. Optional module execution code

The following sections discuss each of these parts.

Namespace

The namespace declaration of each PHP file in the TYPO3 Core shows where the file belongs inside TYPO3 CMS. The namespace starts with TYPO3\CMS, then the extension name in UpperCamelCase, a backslash and then the name of the subfolder of Classes/, in which the file is located (if any). E.g. the file typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php with the class ContentObjectRenderer is in the namespace TYPO3\CMS\Frontend\ContentObject.

use statements can be added to this section.

Namespace Imports

Necessary PHP Classes should be imported like explained in PSR-2:

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;

Put one blank line before and after import statements. Also put one import statement per line.

Class Information Block

The class information block provides basic information about the class in the file. It should include a description of the class. Example:

/**
 * This class provides XYZ plugin implementation.
 */

PHP Class

The PHP class follows the class information block. PHP code must be formatted as described in chapter "PHP syntax formatting".

The class name is expected to follow some conventions. It must be identical to the file name and must be written in upper camel case.

Taking again the example of file typo3/sysext/core/Classes/Cache/Backend/AbstractBackend.php, the PHP class declaration will look like:

class AbstractBackend implements \TYPO3\CMS\Core\Cache\Backend\BackendInterface
{
        
}

Optional Module Execution Code

Module execution code instantiates the class and runs its method(s). Typically this code can be found in eID scripts and old Backend modules. Here is how it may look like:

$controller = GeneralUtility::makeInstance(\Vendor\MyNamespace\MyExtension\Controller\AjaxController::class);
$controller->main();

This code must appear after the PHP class.