mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Allow false/true to be read as keys in Hash::get().
While these are not values within the documented types, there exist use cases in CakeSession that necessitate these to be supported types. Refs #10196
This commit is contained in:
parent
aa8d708b9a
commit
3f10a0227a
2 changed files with 11 additions and 6 deletions
|
@ -236,10 +236,13 @@ class HashTest extends CakeTestCase {
|
|||
*/
|
||||
public function testGetEmptyKey() {
|
||||
$data = array(
|
||||
'' => 'some value'
|
||||
true => 'true value',
|
||||
false => 'false value',
|
||||
'' => 'some value',
|
||||
);
|
||||
$result = Hash::get($data, '');
|
||||
$this->assertSame($data[''], $result);
|
||||
$this->assertSame($data[''], Hash::get($data, ''));
|
||||
$this->assertSame($data[false], Hash::get($data, false));
|
||||
$this->assertSame($data[true], Hash::get($data, true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,7 +252,7 @@ class HashTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testGetInvalidPath() {
|
||||
Hash::get(array('one' => 'two'), true);
|
||||
Hash::get(array('one' => 'two'), new StdClass());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,11 +48,13 @@ class Hash {
|
|||
}
|
||||
if (is_string($path) || is_numeric($path)) {
|
||||
$parts = explode('.', $path);
|
||||
} elseif (is_bool($path) || $path === null) {
|
||||
$parts = [$path];
|
||||
} else {
|
||||
if (!is_array($path)) {
|
||||
throw new InvalidArgumentException(__d('cake_dev',
|
||||
'Invalid Parameter %s, should be dot separated path or array.',
|
||||
$path
|
||||
'Invalid path parameter: %s, should be dot separated path or array.',
|
||||
var_export($path, true)
|
||||
));
|
||||
}
|
||||
$parts = $path;
|
||||
|
|
Loading…
Reference in a new issue