From: Harm Hermsen Date: Wed, 17 Sep 2014 13:34:03 +0000 (+0200) Subject: Possible multiplication of $fResult in $result X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1cba072e4ebd965fe92413b32fa1f787af4483f1;p=civicrm-core.git Possible multiplication of $fResult in $result The old structure allowed for possible multiplication of $fResult in $result when a specific $fnSuffix hook was implemented in one module, but not in another. We only want to add $fResult to $result if $fnName exists, so moved the array_merge() into that if-statement. Furthermore, if $numParams is not case-specified in the switch, at the array_merge(), $fResult could hold the result from a previous module (because in the default case $fResult is not being set), so we have to initialize $fResult to an empty array in the foreach(). --- diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 41f7746d33..3ca5709eb2 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -178,12 +178,13 @@ abstract class CRM_Utils_Hook { // must be reentrant. PHP is finicky about running // multiple loops over the same variable. The circumstances // to reproduce the issue are pretty intricate. - $result = $fResult = array(); + $result = array(); if ($civiModules !== NULL) { foreach ($civiModules as $module) { $fnName = "{$module}_{$fnSuffix}"; if (function_exists($fnName)) { + $fResult = array(); switch ($numParams) { case 0: $fResult = $fnName(); @@ -217,11 +218,11 @@ abstract class CRM_Utils_Hook { CRM_Core_Error::fatal(ts('Invalid hook invocation')); break; } - } - if (!empty($fResult) && - is_array($fResult)) { - $result = array_merge($result, $fResult); + if (!empty($fResult) && + is_array($fResult)) { + $result = array_merge($result, $fResult); + } } } }