View Issue Details

IDProjectCategoryView StatusLast Update
0002184OXID eShop (all versions)1. ----- eShop frontend -----public2012-12-10 14:38
ReporterMoehlis Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version4.4.3 revision 30016 
Fixed in Version4.5.6 revision 40808 
Summary0002184: error in spl implementation of Iterator
Descriptionwhile iterating through an oxlist object using foreach, unsetting the current entry will result in skipping the next entry. thats because the unset is done directly on the object. so while the array loses the current element, it already points to the next one, meaning the next foreach loop will get the one after next.

its a bit complicated, so i'll insert my test code. you will see what will happen if you trying this in an oxid module or portlet, maybe paypal...
Additional Information<?php

class _anzido extends oxUBase
{
    public function init () {
        
        $this->_oxid();
        $this->_php();
        
        die( 'EOF ' . time() );
    }
    
    public function _oxid () {
        
        $oList = oxNew('oxarticlelist');
        
        $oList->selectString ( 'SELECT * FROM oxarticles limit 10' );
        
        foreach ( $oList as $sKey => $oArticle ) {
            echo $oArticle->getId().'
';
            // $oList->rewind(); // this would help but doesnt solve the problem in the implementation
            unset($oList[$sKey]);
        }
    }
    
    public function _php () {
        $it = new MyIterator(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

        foreach ($it as $a => $b) {
            echo $b . '
';
            unset($it[$a]);
        }
    }
}







class MyIterator implements Iterator, arrayaccess
{
    private $var = array();

    public function __construct($array)
    {
        if (is_array($array)) {
            $this->var = $array;
        }
    }

    public function rewind() {
        reset($this->var);
    }

    public function current() {
        $var = current($this->var);
        return $var;
    }

    public function key() {
        $var = key($this->var);
        return $var;
    }

    public function next() {
        $var = next($this->var);
        return $var;
    }

    public function valid() {
        $var = $this->current() !== false;
        return $var;
    }
    
    public function offsetSet($offset, $value) {
        $this->container[$offset] = $value;
    }
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }
}

TagsNo tags attached.
Theme
BrowserAll
PHP Version5.2.9
Database Versionany

Relationships

related to 0003627 resolvedaurimas.gladutis getVariantListExceptCurrent() on easy variant wrong 

Activities

birute_meilutyte

2010-10-29 09:02

reporter   ~0003646

@developers: check from source code side if such issue exist

mindaugas.rimgaila

2011-12-27 11:25

reporter   ~0005530

Fixed oxlist foreach iteration.