File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff 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/**
Original file line number Diff line number Diff 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+ ?>
You can’t perform that action at this time.
0 commit comments