Skip to content

[8.x] Support iterables objects on data_get nested arrays #37443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2021

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