Page MenuHomePhabricator

D15133.id36537.diff
No OneTemporary

D15133.id36537.diff

diff --git a/src/utils/__tests__/PhutilUtilsTestCase.php b/src/utils/__tests__/PhutilUtilsTestCase.php
--- a/src/utils/__tests__/PhutilUtilsTestCase.php
+++ b/src/utils/__tests__/PhutilUtilsTestCase.php
@@ -352,6 +352,9 @@
$this->assertEqual(null, idx($array, 'null', false));
$this->assertEqual(null, idx($array, 'missing'));
$this->assertEqual(false, idx($array, 'missing', false));
+
+ $array = new CaseInsensitiveArray();
+ $this->assertEqual(null, idx($array, 'key'));
}
public function testSplitLines() {
diff --git a/src/utils/utils.php b/src/utils/utils.php
--- a/src/utils/utils.php
+++ b/src/utils/utils.php
@@ -33,7 +33,14 @@
* @return wild If `$array[$key]` exists, that value is returned. If not,
* $default is returned without raising a warning.
*/
-function idx(array $array, $key, $default = null) {
+function idx($array, $key, $default = null) {
+ if (!(is_array($array) || $array instanceof ArrayAccess)) {
+ throw new InvalidArgumentException(
+ sprintf(
+ 'Argument passed to %s must be an array.',
+ __FUNCTION__));
+ }
+
// isset() is a micro-optimization - it is fast but fails for null values.
if (isset($array[$key])) {
return $array[$key];

File Metadata

Mime Type
text/plain
Expires
Thu, May 9, 5:10 AM (2 w, 15 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6266880
Default Alt Text
D15133.id36537.diff (1 KB)

Event Timeline