php-judy icon indicating copy to clipboard operation
php-judy copied to clipboard

Judy::rewind() - undefined method?

Open intel352 opened this issue 12 years ago • 5 comments

Attempting to use rewind() w/ Judy 0.1.6, results in the error: FatalErrorException: Error: Call to undefined method Judy::rewind()

Supposedly Judy implements Iterator, which requires rewind(), but it's not listed in the method list in the manual, and attempting to access rewind() results in an error. So does Judy implement Iterator or not?

http://www.php.net/manual/en/class.judy.php < even shows here that Judy implements Iterator.

intel352 avatar Apr 01 '13 07:04 intel352

The iterator method are implemented so a Judy object can be used in a foreach. The implementation is done overloading the zend_object_iterator. Methods are currently not exposed at the php level. I will look at exposing the missing methods.

orieg avatar Apr 01 '13 07:04 orieg

That would be appreciated, having a bit of trouble trying to use Judy w/ the SPL iterators & classes.

Attempted to extend Judy w/ a class that implemented Iterator or IteratorAggregate, received error that it could not implement X interface. Additionally, Judy::next() definition may conflict w/ what's expected of Iterator, so that may be an issue...

intel352 avatar Apr 01 '13 08:04 intel352

I've worked around it by building a class implementing Iterator, ArrayAccess, Countable, using Judy as a private property within. Would be quite awesome if my custom class were (at least partially) obsoleted by similar implementation in Judy ;-)

If I knew C & had the time, I'd contribute

intel352 avatar Apr 01 '13 08:04 intel352

I will definitely look into this. Depending on my schedule, I may be able to get something out by end of week.

orieg avatar Apr 01 '13 14:04 orieg

@orieg this means you are not implementing Iterator. You are providing iteration support only (and you should at least implement Traversable, which would advocate this support to userland code, and allow to wrap it in an IteratorIterator if a real Iterator is needed)

stof avatar Dec 07 '15 11:12 stof