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

Arrays::get is not type strict #91

@mirfilip

Description

@mirfilip

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions