mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Use array_key_exists instead of isset()
This allows contains() to work with null values. Fixes #4083
This commit is contained in:
parent
68aefe7eda
commit
a30f861f2c
2 changed files with 8 additions and 2 deletions
|
@ -593,6 +593,12 @@ class HashTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTrue(Hash::contains($b, $a));
|
$this->assertTrue(Hash::contains($b, $a));
|
||||||
$this->assertFalse(Hash::contains($a, $b));
|
$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')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -442,14 +442,14 @@ class Hash {
|
||||||
$val = $needle[$key];
|
$val = $needle[$key];
|
||||||
unset($needle[$key]);
|
unset($needle[$key]);
|
||||||
|
|
||||||
if (isset($data[$key]) && is_array($val)) {
|
if (array_key_exists($key, $data) && is_array($val)) {
|
||||||
$next = $data[$key];
|
$next = $data[$key];
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
|
|
||||||
if (!empty($val)) {
|
if (!empty($val)) {
|
||||||
$stack[] = array($val, $next);
|
$stack[] = array($val, $next);
|
||||||
}
|
}
|
||||||
} elseif (!isset($data[$key]) || $data[$key] != $val) {
|
} elseif (!array_key_exists($key, $data) || $data[$key] != $val) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue