Skip to content

Commit 8f9a08f

Browse files
Merge branch 'kevin-foster-is_hash_undefined_offset' into 1.1-dev
2 parents ddce812 + a52efcb commit 8f9a08f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/Utils.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ function array_flatten(array $array)
6363
/**
6464
* Somewhat naive way to determine if an array is a hash.
6565
*/
66-
function is_hash(&$array)
66+
function is_hash($array)
6767
{
68-
if (!is_array($array))
68+
if (!is_array($array)) {
6969
return false;
70+
}
7071

7172
$keys = array_keys($array);
72-
return @is_string($keys[0]) ? true : false;
73+
74+
return isset($keys[0]) && is_string($keys[0]);
7375
}
7476

7577
/**

test/UtilsTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,20 @@ public function test_wrap_strings_in_arrays()
103103
$x = '1';
104104
$this->assert_equals(array(array('1')),ActiveRecord\wrap_strings_in_arrays($x));
105105
}
106-
}
107-
106+
107+
public function test_is_hash()
108+
{
109+
$hash = array('key' => 'value');
110+
$this->assert_true(ActiveRecord\is_hash($hash));
111+
112+
$notHash = array(0 => 'value');
113+
$this->assert_false(ActiveRecord\is_hash($notHash));
114+
}
115+
116+
public function test_is_hash_empty_array()
117+
{
118+
$notHash = array();
119+
$this->assert_false(ActiveRecord\is_hash($notHash));
120+
}
121+
};
122+
?>

0 commit comments

Comments
 (0)