---
title: "File structure"
manual: "TYPO3 Explained"
version: "main"
permalink: "https://docs.typo3.org/permalink/t3coreapi:cgl-file-structure@main"
source: "CodingGuidelines/CglPhp/FileStructure.rst"
rendered: "2026-09-24T12:36:55+00:00"
---

# File structure {#cgl-file-structure}

TYPO3 files use the following structure:

1.  Opening PHP tag (including strict_types declaration)
1.  Copyright notice
1.  Namespace
1.  Namespace imports
1.  Class information block in phpDoc format
1.  PHP class
1.  Optional module execution code

The following sections discuss each of these parts.

## Namespace {#cgl-file-structure-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.

## Copyright notice {#cgl-file-structure-copyright-notice}

TYPO3 is released under the terms of GNU General Public License
version 2 or any later version. The copyright notice with a reference
to the license text must be included at the top of every TYPO3 PHP class
file. User files must have this copyright notice as well. Example:

**EXT:some_extension/Classes/SomeClass.php**

```php
<?php
declare(strict_types = 1);

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

 namespace Vendor\SomeExtension\SomeFolder;
```

The wording must not be changed/updated/extended, under any circumstances.

## Namespace imports {#cgl-file-structure-namespace-imports}

Necessary PHP classes should be imported like explained in the
[TYPO3 Coding Standards](https://github.com/TYPO3/coding-standards),
(based on PER-CS1.0 / PSR-12 at the time of this writing, transitioning towards
PER-CS2.0):

**EXT:some_extension/Classes/SomeClass.php**

```php
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Cache\Backend\BackendInterface;
```

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

## Class information block {#cgl-file-structure-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:

**EXT:some_extension/Classes/SomeClass.php**

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

## PHP class {#cgl-namespaces-class-names}

The PHP class follows the class information block. PHP code must be formatted
as described in chapter ["PHP syntax formatting"](https://docs.typo3.org/permalink/t3coreapi:cgl-php-syntax-formatting@main).

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.

The namespace and class names of user files follow the same rules as
class names of the TYPO3 Core files do.

The namespace declaration of each user file should show where the file
belongs inside its extension. The namespace starts with
`"VendorMyNamespace"`, where "Vendor" is your vendor name and
"MyNamespace" is the extension name in UpperCamelCase. Then follows the
name of the subfolder of `Classes/`, in which the file is located
(if any). E.g. the file
[`EXT:realurl/Classes/Controller/AliasesController.php`](../../ExtensionArchitecture/FileStructure/Classes/Index.md#file-extension-classes-controller-somecontroller-php)
with the class `AliasesController` is in the namespace
"`\DmitryDulepov\Realurl\Controller`".

A PHP class declaration looks like the following:

**EXT:some_extension/Classes/SomeClass.php**

```php
class SomeClass extends AbstractBackend implements BackendInterface
{
    // ...
}
```

## Optional module execution code {#cgl-file-structure-optional-module-execution}

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:

**EXT:some_extension/Classes/SomeClass.php**

```php
$someClass = GeneralUtility::makeInstance(SomeClass::class);
$someClass->main();
```

This code must appear **after** the PHP class.
