From 6b4be82dbcef7982e2de82f7f0c3d4feaa762f74 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 5 Jul 2022 16:33:17 -0700 Subject: [PATCH] dev/core#3181 - Resolver - Compatibility fix for GLOBALS in PHP 8.1 --- Civi/Core/Resolver.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Civi/Core/Resolver.php b/Civi/Core/Resolver.php index a3950c74e9..67d4689117 100644 --- a/Civi/Core/Resolver.php +++ b/Civi/Core/Resolver.php @@ -251,7 +251,8 @@ class ResolverApi { class ResolverGlobalCallback { private $mode; - private $path; + private $basePath; + private $subPath; /** * Class constructor. @@ -259,10 +260,13 @@ class ResolverGlobalCallback { * @param string $mode * 'getter' or 'setter'. * @param string $path + * Ex: 'dbLocale' <=> $GLOBALS['dbLocale'] + * Ex: 'civicrm_setting/domain/debug_enabled' <=> $GLOBALS['civicrm_setting']['domain']['debug_enabled'] */ public function __construct($mode, $path) { $this->mode = $mode; - $this->path = $path; + $this->subPath = explode('/', $path); + $this->basePath = array_shift($this->subPath); } /** @@ -273,11 +277,12 @@ class ResolverGlobalCallback { * @return mixed */ public function __invoke($arg1 = NULL) { + // For PHP 8.1+ compatibility, we resolve the first path-item before doing any array operations. if ($this->mode === 'getter') { - return \CRM_Utils_Array::pathGet($GLOBALS, explode('/', $this->path)); + return \CRM_Utils_Array::pathGet($GLOBALS[$this->basePath], $this->subPath); } elseif ($this->mode === 'setter') { - \CRM_Utils_Array::pathSet($GLOBALS, explode('/', $this->path), $arg1); + \CRM_Utils_Array::pathSet($GLOBALS[$this->basePath], $this->subPath, $arg1); return NULL; } else { -- 2.25.1