From: Tim Otten Date: Tue, 5 Jul 2022 23:33:17 +0000 (-0700) Subject: dev/core#3181 - Resolver - Compatibility fix for GLOBALS in PHP 8.1 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6b4be82dbcef7982e2de82f7f0c3d4feaa762f74;p=civicrm-core.git dev/core#3181 - Resolver - Compatibility fix for GLOBALS in PHP 8.1 --- 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 {