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

Actually reverted this - too big of a risk of breaking existing applications that aren't expecting this behavior.

@marcoocram
Copy link
Contributor Author

Any possibility to apply this kind of behaviour on the future?

How can we afford this behaviour?

@BrandonSurowiec
Copy link
Contributor

@marcoocram You could try targeting the master branch for 9.x.

@marcoocram
Copy link
Contributor Author

Maybe....

But i don't think this is a BC, if someone is using an iterable on data_get with the "*" is doing something wrong because it will return always null right? Is a bad behaviour...

@marcoocram
Copy link
Contributor Author

reopened to [9.x] => #37453

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.

3 participants