Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15335842
D15133.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D15133.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 9, 5:38 PM (2 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7390202
Default Alt Text
D15133.diff (1 KB)
Attached To
Mode
D15133: Allow objects implementing `ArrayAccess` to the passed to `idx`
Attached
Detach File
Event Timeline
Log In to Comment