From:             jpetso at gmx dot at
Operating system: all
PHP version:      5.3.0alpha3
PHP Bug Type:     SPL related
Bug description:  DualIterator example uses wrong constants

Description:
------------
Regarding the DualIterator example, current version:
http://cvs.php.net/viewvc.cgi/php-

In its API documentation, the key() method claims to use the
DualIterator::KEY_* constants, but the code makes use of CURRENT_*
instead.

Also, does the *_ARRAY option (which is used by default even for
key()) does not make a lot of sense because arrays cannot be used as
keys at least for foreach loops. (Might work with low-level iterator
usage, but then again keys should probably be *real* keys in any
case.)

It would be nice to have these issues fixed (diff attached further
down).

Related feature request, totally not in scope for this bug report
(sorry): it might be worthwhile to extend the flags to
{CURRENT,KEY}_{LHS,RHS}_{KEY,VALUE} in order to make it possible to
e.g. use the left hand side's current value as key for the iterator.
At least, that's what I'm going to use my derived class for.

Thanks for having a look (and for your work on PHP), regards,
  Jakob

Reproduce code:
---------------
$leftSideArray = array('lhs_key' => 'lhs_value');
$rightSideArray = array('rhs_key' => 'rhs_value');

$combined = new DualIterator(
  new ArrayIterator($leftSideArray), new ArrayIterator($rightSideArray),
  DualIterator::KEY_LHS | DualIterator::CURRENT_RHS
);

foreach ($combined as $key => $value) {
  var_dump($key);
  var_dump($value);
}

Expected result:
----------------
string(7) "lhs_key"
string(9) "rhs_value"

Actual result:
--------------
Warning: Illegal type returned from DualIterator::key() in
/home/jakob/dev/www/drupal/6/transformations/sites/all/modules/tf_modu
line 223

Call Stack:
    0.0014     112544   1. {main}()
/home/jakob/dev/www/drupal/6/transformations/sites/all/modules/tf_modu

int(0)
string(9) "rhs_value"

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

Reply via email to