Skip to content
Snippets Groups Projects
Commit 6b4be82d authored by totten's avatar totten
Browse files

#3181 - Resolver - Compatibility fix for GLOBALS in PHP 8.1

parent bbb4b90a
Branches
Tags
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment