Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Discovered by PHPStan in #3178534: Start running PHPStan on Drupal core (level 0)
\Drupal\Core\Database\Driver\mysql\Connection::serialize() reads as follows:
/**
* {@inheritdoc}
*/
public function serialize() {
// Cleanup the connection, much like __destruct() does it as well.
if ($this->needsCleanup) {
$this->nextIdDelete();
}
$this->needsCleanup = FALSE;
return parent::serialize();
}
However the parent class has no serialize()
method, and it does not implement the Serializable interface.
Steps to reproduce
Try to call serialize()
directly:
>>> \Drupal::database()->serialize();
PHP Error: Call to undefined method Drupal/Core/Database/Connection::serialize() in /var/www/html/drupal/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php on line 213
Proposed resolution
Remove this code.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#2 | 3210888.patch | 722 bytes | longwave |
Comments
Comment #2
longwaveComment #3
longwaveThis method was originally added in #1990544: Convert system_modules() to a Controller as a fix for when we serialized services. A followup was added to add a test for this in #2039731: Add test for cleaning up connection upon serialization but closed as not needed as we stopped serializing services, but this code was not removed from the driver.
Comment #5
mondrakeThanks
Comment #7
larowlanCommitted 3911088 and pushed to 9.3.x. Thanks!
Backported to 9.2.x
Getting a second opinion on backporting to 9.1
Comment #8
larowlanThis is only a normal bug so after discussing with catch, decided to not backport as there's no pressing need for it