Skip to content

Conversation

@marcoocram
Copy link
Contributor

Using data_get helper to get properties on nested arrays is only available if the object is an array or Collection.

This PR allows to get data from any "iterable" object.

Example:

class IterableObject implements IteratorAggregate
{
    protected $items = [];

    public function __construct($items = [])
    {
        $this->items = $items;
    }

    public function getIterator()
    {
        return new ArrayIterator($this->items);
    }
}

$object = new IterableObject([
    ['data' => 'hello'],
    ['data' => 'world'],
]);

data_get($object, '*.data');
// ["hello", "world"]

@taylorotwell
Copy link
Member

Why on master? What is the breaking change?

@marcoocram
Copy link
Contributor Author

I don't think this will be a BC, but you revert the PR on 8.x branch because risk of change (on existing projects) so maybe this could be the BC...

#37443 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants