From:             
Operating system: Any
PHP version:      5.2.13
Package:          SPL related
Bug Type:         Bug
Bug description:LimitIterator cannot take IteratorAggregate inner iterator

Description:
------------
LimitIterator declares in its constructor that it only takes an Iterator as
its inner iterator rather than just a Traversable as its parent
IteratorIterator does.  That becomes a problem when, for example, an object
that implements IteratorAggregate is passed into a LimitIterator.  Although
IteratorAggregate will produce an Iterator via its getIterator() method, it
is not itself an Iterator, just Traversable, so LimitIterator will reject
it.



I'm running my code on PHP 5.2.6 but according to the documentation this is
an issue in 5.3 still.  Technically this behavior is what the documentation
currently reads, but I believe it is a bug that LimitIterator demands an
Iterator, not just a Traversable, and therefore breaks in this case.

Test script:
---------------
class Foo implements IteratorAggregate {

  protected $array = array(1, 2, 3, 4, 5);

  public function getIterator() {

    return new ArrayIterator($this->array);

  }

}



$f = new LimitIterator(new Foo(), 0, 3);

foreach ($f as $a) {

  print $a . PHP_EOL;

}

Expected result:
----------------
1

2

3

Actual result:
--------------
Catchable fatal error: Argument 1 passed to LimitIterator::__construct()
must implement interface Iterator, instance of Foo given in
/blah/blah/test.php on line 10

-- 
Edit bug report at http://bugs.php.net/bug.php?id=52280&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52280&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52280&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52280&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52280&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52280&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52280&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52280&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52280&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52280&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52280&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52280&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52280&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52280&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52280&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52280&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52280&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52280&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52280&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52280&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52280&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52280&r=mysqlcfg

Reply via email to