From: eileen Date: Mon, 1 Feb 2021 01:40:17 +0000 (+1300) Subject: [REF] do not needlessly pass as reference, enforce valid param X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f062e02d0596f517da32389165005aaa71cb6ae6;p=civicrm-core.git [REF] do not needlessly pass as reference, enforce valid param --- diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 5ecdb554d5..ec6ecffd2b 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -61,20 +61,17 @@ class CRM_Utils_Array { * @return mixed * The value of the key, or null if the key is not found. */ - public static function retrieveValueRecursive(&$params, $key) { - if (!is_array($params)) { - return NULL; - } - elseif ($value = CRM_Utils_Array::value($key, $params)) { - return $value; + public static function retrieveValueRecursive(array $params, string $key) { + if (isset($params[$key])) { + return $params[$key]; } - else { - foreach ($params as $subParam) { - if (is_array($subParam) && - $value = self::retrieveValueRecursive($subParam, $key) - ) { - return $value; - } + foreach ($params as $subParam) { + if (is_array($subParam) && + // @todo - this will mishandle values like 0 and false + // but it's a little scary to fix. + $value = self::retrieveValueRecursive($subParam, $key) + ) { + return $value; } } return NULL;