neomerx/json-api

Not using Traversable

Closed this issue · 8 comments

Parser line 245

elseif (($data instanceof Iterator && ($iterator = $data) !== null) ||
            ($data instanceof IteratorAggregate && ($iterator = $data->getIterator()) !== null)
        ) {

This is very limiting to look for Iterator instead of Traversable. We have encountered errors and spent ages trying to debug this when using Ds\Set as an iterable container to our classes.

php-ds comes in two flavours; a composer library and a C library extension. The composer library Set class implements IteratorAggregate but not the C library, as it can just be Traversable.

Can this library be updated to account for Traversable classes instead of Iterator?

The library needs to know if $data have anything inside without iterating the data.

Based on Traversable interface description it seems more like a bug in C implementation for php-ds.

Abstract base interface that cannot be implemented alone. Instead it must be implemented by either IteratorAggregate or Iterator.

However, I've got an idea how to answer this question indirectly which I'm trying at the moment.

Please check it out from branch issue202 and let me know if it works for you.

Thanks for looking at this.

I can see the confusion re the 'cannot implement alone'; this is aimed at PHP developers explaining that you cannot use this interface in your PHP classes, but from a C level this would be perfectly acceptable for the language developers.

I really appreciate the quick response on this, and we are testing this out now. :)

PS, I am raising this with the php-ds devs also to see what their thoughts are.

Thanks.

So this is tested and solves the problem. It turns out we were still on a v1.x release so have to do some upgrades anyway :)

Can I ask how close this dev branch is to release stage? Could this code be pulled out into a hotfix release off the current stable tag, as there is also a lot of other changes in there.

I have to have our codebase running on stable releases of third party code sadly.

Released as 2.0.2

Typically code fixes and improvements go to main code base very quickly. The project has vast testing code base (100% code coverage) so I have a high level of confidence in the project.

Also core code base is stable for a very long time.

Your support for the project 🌟 would be appreciated 😉

You are a star for getting this done for us so quickly! How do I support the project?

Edit: Oh right, of course ;)

Thanks