Breaking: #108285 - Core uses __serialize() and __unserialize() methods 

See forge#108285

Description 

PHP 8.5 deprecates the magic methods __sleep() and __wakeup() in favor of __serialize() and __unserialize() . All TYPO3 Core classes have been migrated to the new methods:

  • Logger
  • FileReference
  • BlockSerializationTrait
  • Query
  • QueryResult
  • Typo3QuerySettings
  • ReflectionService
  • FinisherVariableProvider

AbstractDomainObject , the base class of all Extbase entities and value objects, implements __serialize() and __unserialize() as well.

The internal deserializer used by Registry and by upgrade wizards now also rejects classes with a user-defined __unserialize() method, unless that method is provided by BlockSerializationTrait or the class is listed in $GLOBALS['TYPO3_CONF_VARS']['SYS']['deserialization']['allowedClassNames'] .

Impact 

When a class or one of its parents implements __serialize() or __unserialize() , PHP no longer calls __sleep() or __wakeup() . 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 __sleep() or __wakeup() in a class extending one of the classes mentioned above, especially in Extbase domain models extending AbstractEntity or AbstractValueObject , or that call parent::__sleep() or parent::__wakeup() of these classes.

Migration 

Replace __sleep() with __serialize() , which returns an array of the data to be serialized, and __wakeup() with __unserialize() , which receives that array and restores the object state. Call the parent methods where the parent class implements them:

Before
public function __sleep(): array
{
    return ['title'];
}

public function __wakeup(): void
{
    $this->initializeRuntimeState();
}
Copied!
After
public function __serialize(): array
{
    return ['title' => $this->title];
}

public function __unserialize(array $data): void
{
    $this->title = $data['title'];
    $this->initializeRuntimeState();
}
Copied!

Flush all caches after the update. Pending form submissions and session data containing serialized objects of the affected classes have to be re-created.