diff --git a/CRM/Utils/Array.php b/CRM/Utils/Array.php index 1f1d1d6001b7..01831bd34341 100644 --- a/CRM/Utils/Array.php +++ b/CRM/Utils/Array.php @@ -26,7 +26,7 @@ class CRM_Utils_Array { * * @param string $key * Key value to look up in the array. - * @param array $list + * @param array|ArrayAccess $list * Array from which to look up a value. * @param mixed $default * (optional) Value to return $list[$key] does not exist. @@ -38,6 +38,10 @@ public static function value($key, $list, $default = NULL) { if (is_array($list)) { return array_key_exists($key, $list) ? $list[$key] : $default; } + if ($list instanceof ArrayAccess) { + return $list[$key]; + } + CRM_Core_Error::deprecatedFunctionWarning('You have passed an invalid parameter for the "list"'); return $default; } diff --git a/tests/phpunit/Civi/Payment/PropertyBagTest.php b/tests/phpunit/Civi/Payment/PropertyBagTest.php index 797596a418f6..770c296fad0b 100644 --- a/tests/phpunit/Civi/Payment/PropertyBagTest.php +++ b/tests/phpunit/Civi/Payment/PropertyBagTest.php @@ -191,6 +191,15 @@ public function testRequire() { } } + /** + * Test retrieves using CRM_Utils_Array::value still work. + */ + public function testUtilsArray() { + $propertyBag = new PropertyBag(); + $propertyBag->setContactID(123); + $this->assertEquals(123, \CRM_Utils_Array::value('contact_id', $propertyBag)); + } + /** * * Data provider for testOtherParams