Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Arrays::get is not type strict #91

Open
mirfilip opened this issue Apr 19, 2016 · 0 comments
Open

Arrays::get is not type strict #91

mirfilip opened this issue Apr 19, 2016 · 0 comments

Comments

@mirfilip
Copy link

mirfilip commented Apr 19, 2016

There are two problems when using Arrays::get($data, $path, $default);

Consider such input:

$data = [
    'foo' => null,
];
  1. When $key is a dot notation for a path that doesn't exist, $default is returned. By default, it'd be null. One can work around this problem as $default can be a Closure. Sth like Arrays::get($data, $path, function() { throw new \Exception('Item not found'); }); works but is just a workaround for another problem. Example:
    Arrays::get($data, 'foo.bar.baz'); returns null.
  2. When $key exists but the value is null, it would be treated as not existing. Example: Arrays::get($data, 'foo', 'the value does not exist'); returns the value does not exist

Both problems stem from the fact of using isset() instead of array_key_exists(). It's trivial to fix the issue but it'd introduce BC breaks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant