diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 67adfc9db17..ebfa9c520d9 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -593,6 +593,12 @@ public function testContains() { ); $this->assertTrue(Hash::contains($b, $a)); $this->assertFalse(Hash::contains($a, $b)); + + $a = array(0 => 'test', 'string' => null); + $this->assertTrue(Hash::contains($a, array('string' => null))); + + $a = array(0 => 'test', 'string' => null); + $this->assertTrue(Hash::contains($a, array('test'))); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 8cc99977ae2..e12f14c5fe4 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -442,14 +442,14 @@ public static function contains(array $data, array $needle) { $val = $needle[$key]; unset($needle[$key]); - if (isset($data[$key]) && is_array($val)) { + if (array_key_exists($key, $data) && is_array($val)) { $next = $data[$key]; unset($data[$key]); if (!empty($val)) { $stack[] = array($val, $next); } - } elseif (!isset($data[$key]) || $data[$key] != $val) { + } elseif (!array_key_exists($key, $data) || $data[$key] != $val) { return false; }