From:             admin at ifyouwantblood dot de
Operating system: 
PHP version:      5.3.0
PHP Bug Type:     Feature/Change Request
Bug description:  make current(),key(),next() etc. check for Iterator

Description:
------------
it would be helpful for chained Iterators, if the default array functions
would check if an given object is an instanceof Iterator and react
appropriate.

thus key() calling object->key(), current() calling object->current() and
so on.

Reproduce code:
---------------
<?php

class iterator_array implements Iterator
{
        protected $aarray;
        
        public function __construct($array)
        {
                $this->aarray=$array;
        }
                
        public function key()
        {
                return key($this->aarray);
        }
                
        public function current()
        {
                return current($this->aarray);
        }
                
        public function valid()
        {
                return (current($this->aarray)!==FALSE);
        }
                
        public function next()
        {
                next($this->aarray);
        }
                
        public function rewind()
        {
                reset($this->aarray);
        }
}

$i=new iterator_array(Array(1,2));
var_dump(current($i));
var_dump(key($i));
next($i);
var_dump($current($i));
var_dump(key($i));

Expected result:
----------------
int(1)
int(0)
int(2)
int(1)


Actual result:
--------------
array(6) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
}
string(9) "&#65533;*&#65533;aarray"
bool(false)
NULL


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

Reply via email to