Breaking: #108285 - Core uses __serialize() and __unserialize() methods
See forge#108285
Description
PHP 8.5 deprecates the magic methods
__ and
__
in favor of
__ and
__. All TYPO3 Core
classes have been migrated to the new methods:
LoggerFileReference BlockSerialization Trait QueryQueryResult Typo3QuerySettings ReflectionService FinisherVariable Provider
Abstract, the base
class of all Extbase entities and value objects, implements
__ and
__ as well.
The internal deserializer used by
Registry
and
by upgrade wizards now also rejects classes with a user-defined
__ method, unless that method is provided by
Block or the class is
listed in
$GLOBALS.
Impact
When a class or one of its parents implements
__ or
__, PHP no longer calls
__ or
__. Such methods in classes extending one of the classes above,
including any Extbase domain model, are silently ignored.
Serialized data written before the update, for example in caches, sessions or the state of a form, may no longer be restored correctly.
Affected installations
Installations with extensions that implement
__ or
__ in a class extending one of the classes mentioned above,
especially in Extbase domain models extending
Abstract or
Abstract, or that
call
parent::__ or
parent::__ of these classes.
Migration
Replace
__ with
__, which returns an array of
the data to be serialized, and
__ with
__,
which receives that array and restores the object state. Call the parent
methods where the parent class implements them:
public function __sleep(): array
{
return ['title'];
}
public function __wakeup(): void
{
$this->initializeRuntimeState();
}
public function __serialize(): array
{
return ['title' => $this->title];
}
public function __unserialize(array $data): void
{
$this->title = $data['title'];
$this->initializeRuntimeState();
}
Flush all caches after the update. Pending form submissions and session data containing serialized objects of the affected classes have to be re-created.