Breaking: #107229 - Removed support for annotations in Extbase
See forge#107229
Description
Extbase no longer supports PHP annotations for models, data transfer objects
(DTOs), and controller actions. Use PHP attributes (for example
#) instead. Attributes provide the same functionality
with better performance and native language support.
Note
With this change, the third-party library doctrine/annotations is no longer required by Extbase. The library itself recommends switching to PHP attributes since version 1.14.0 and has been marked as abandoned.
Important
PHPDoc annotations such as
@var,
@return, and similar are
unaffected by this change, as they are handled by standard PHPDoc parsing,
not by Doctrine.
Explicit type annotations like
@var Object
remain fully supported.
Extbase previously relied on annotation parsing, typically detected when the annotation namespace was imported, for example:
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class MyModel extends AbstractEntity
{
/**
* @Extbase\Validate("NotEmpty")
*/
protected string $foo = '';
}
Since TYPO3 now requires PHP 8.2 as the minimum version, the use of native PHP attributes is preferred. All Extbase-related annotations have been available as PHP attributes since TYPO3 v12.
Impact
By dropping support for Extbase annotations, only PHP attributes are now supported. This provides more type safety and better integration with PHP’s language features. Developers benefit from a cleaner, faster, and more reliable implementation without the need for the deprecated third-party annotation parser.
Affected installations
All Extbase models, Data Transfer Objects (DTOs), and controllers that use
Extbase annotations are affected.
This includes built-in annotations such as
Cascade,
Lazy, and
Validate, as well as any custom annotation implementations.
Migration
Switch from Extbase annotations to native PHP attributes.
Before (with annotations)
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class MyModel extends AbstractEntity
{
/**
* @Extbase\Validate("NotEmpty")
*/
protected string $foo = '';
}
After (with PHP attributes)
use TYPO3\CMS\Extbase\Attribute as Extbase;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class MyModel extends AbstractEntity
{
#[Extbase\Validate(['validator' => 'NotEmpty'])]
protected string $foo = '';
}
Note
Attribute class namespaces have moved from
\TYPO3\ to
\TYPO3\.
A class alias map remains available for backward compatibility, but since
the old namespaces are deprecated, developers should migrate to the new
Attribute namespace to prevent issues in the future.