Breaking: #107315 - Cache Backend and Frontend related changes
See forge#107315
Description
In TYPO3 v14, the PHP code for the Cache Backend and Cache Frontend has undergone major changes, which may affect extensions:
- Most PHP code from Cache Backends and Cache Frontends is now strongly typed using PHP's native typing system
- Method signatures now use proper type declarations for parameters and return types
- The
mixedtype is now used where appropriate for flexible data handling - All string parameters and boolean return types are properly declared
The following interfaces have been updated with strict typing:
\TYPO3\CMS\ Core\ Cache\ Backend\ Backend Interface \TYPO3\CMS\ Core\ Cache\ Backend\ Php Capable Backend Interface \TYPO3\CMS\ Core\ Cache\ Backend\ Transient Backend Interface \TYPO3\CMS\ Core\ Cache\ Frontend\ Frontend Interface
Additionally, backward compatibility for the abstract base class constructor has been removed:
\TYPO3\CMS\ Core\ Cache\ Backend\ Abstract Backend
Impact
If you are using or extending the Cache Backend or Cache Frontend, you must ensure that you are using the correct PHP types. This includes method parameters, return types, and property types in your classes.
Affected installations
All installations that extend or implement cache backend or frontend classes are affected. This includes custom cache implementations in third-party extensions.
Extension authors who have created custom cache backends or frontends will need to update their class method signatures to match the new type declarations from the interfaces.
Migration
Update your custom cache backend and frontend implementations to use the correct PHP types:
- Ensure all method signatures match the interface declarations exactly
- Add proper type hints for parameters (e.g.,
string $entry)Identifier - Add proper return type declarations (e.g.,
bool,mixed,void) - Update any extending classes to use the same type declarations
Example migration for a custom backend:
use TYPO3\CMS\Core\Cache\Backend\BackendInterface;
// Before (TYPO3 v13)
class MyCustomBackend implements BackendInterface
{
public function get($entryIdentifier)
{
// implementation
}
public function has($entryIdentifier)
{
// implementation
}
}
// After (TYPO3 v14)
class MyCustomBackend implements BackendInterface
{
public function get(string $entryIdentifier): mixed
{
// implementation
}
public function has(string $entryIdentifier): bool
{
// implementation
}
}
Example migration for a custom backend extending AbstractBackend:
use TYPO3\CMS\Core\Cache\Backend\AbstractBackend;
// Before (TYPO3 v13)
class MyCustomBackend extends AbstractBackend
{
public function __construct($context, array $options = [])
{
parent::__construct($context, $options);
}
}
// After (TYPO3 v14)
class MyCustomBackend extends AbstractBackend
{
public function __construct(array $options = [])
{
parent::__construct($options);
}
}
Note for extensions that strive for TYPO3 v13 and v14 compatibility: The
__ change of
\TYPO3\ can be mitigated by
omitting a type for the first argument and checking whether its incoming
value is a string (v13) or an array (v14).
For interface changes that added types to method argument signatures, implementing services may omit the type to keep backwards compatibility with TYPO3 v13. For added return value types, they must be added for v14 compatibility, and v13 should accept them. All in all, it should be possible to have a single implementing class for both v13 and v14, but it may be somewhat tricky. From a code perspective, it may be easier to have dedicated classes.