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

Check for Traversable before Jsonable in EnumeratesValues::getArrayableItems() #2556

Open
bradleybensmith opened this issue Mar 27, 2021 · 1 comment

Comments

@bradleybensmith
Copy link

  • Laravel Version: 8.34.0
  • PHP Version: 8.0.2
  • Database Driver & Version: N/A

Description:

Shouldn't EnumeratesValues::getArrayableItems() check for Traversable before Jsonable? The Jsonable and JsonSerializable result in an array of stdClass objects where Traversable would preserve the correct class objects.

https://github.com/laravel/framework/blob/8.x/src/Illuminate/Collections/Traits/EnumeratesValues.php#L923

        } elseif ($items instanceof Jsonable) {
            return json_decode($items->toJson(), true);
        } elseif ($items instanceof JsonSerializable) {
            return (array) $items->jsonSerialize();
        } elseif ($items instanceof Traversable) {
            return iterator_to_array($items);
        }

As a workaround, I'm currently having to call iterator_to_array when instantiating a Collection since the (3rd party) class I'm using only implements JsonSerializable and IteratorAggregate (Traversable).

@driesvints
Copy link
Member

Heya, thanks for submitting this.

This seems like a feature request or an improvement so I'm moving this to the ideas repository instead. It's best to post these in the ideas repository in the future to get support for your idea. After that you may send a PR to the framework. Please only use the laravel/framework issue tracker to report bugs and issues with the framework.

Thanks!

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

2 participants