From 84a6dadd957aa4dd42f96bb9301201fcf4a1e529 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 10 May 2021 22:22:48 +0100 Subject: [PATCH] Issue #3145563 by Charlie ChX Negyesi, NigelCunningham, alexpott, joachim, longwave, catch, tyler36: Route serialization incompatibilities between PHP 7.4 and 7.3 (9.x only) --- core/lib/Drupal/Core/Routing/Router.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Routing/Router.php b/core/lib/Drupal/Core/Routing/Router.php index 8b649a3ec2a2..cbc20c5987b2 100644 --- a/core/lib/Drupal/Core/Routing/Router.php +++ b/core/lib/Drupal/Core/Routing/Router.php @@ -107,7 +107,19 @@ class Router extends UrlMatcher implements RequestMatcherInterface, RouterInterf * {@inheritdoc} */ public function matchRequest(Request $request) { - $collection = $this->getInitialRouteCollection($request); + try { + $collection = $this->getInitialRouteCollection($request); + } + // PHP 7.4 introduces changes to its serialization format, which mean that + // older versions of PHP are unable to unserialize data that is serialized + // in PHP 7.4. If the site's version of PHP has been downgraded, then + // attempting to unserialize routes from the database will fail, and so the + // router needs to be rebuilt on the current PHP version. + // See https://www.php.net/manual/en/migration74.incompatible.php. + catch (\TypeError $e) { + \Drupal::service('router.builder')->rebuild(); + $collection = $this->getInitialRouteCollection($request); + } if ($collection->count() === 0) { throw new ResourceNotFoundException(sprintf('No routes found for "%s".', $this->currentPath->getPath())); }