New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator::offsetUnset() rewinds the iterator and causes multiple iterations #4

Closed
dnaber-de opened this Issue Mar 28, 2015 · 0 comments

Comments

1 participant
@dnaber-de
Member

dnaber-de commented Mar 28, 2015

Here's a code sample which shows the behavior:

<?php  # -*- coding: utf-8 -*-

$array = [
    'one'   => '1',
    'two'   => '2',
    'three' => '3',
    'four'  => '4'
];
$iterator = new ArrayIterator( $array );

while ( $iterator->valid() ) {

    if ( 'three' === $iterator->key() )
        $iterator->offsetUnset( 'three' );

    var_dump( $iterator->key() );
    $iterator->next();
}

As the EntityFieldsIterator is meant to unset fields following the conditions of the handlers, a unset-handler at the end of the field list will cause the iterator to walk twice over the complete object.

This is no problem for data consistency if the handlers are implemented correctly but of course a performance issue.

@dnaber-de dnaber-de self-assigned this Mar 28, 2015

@dnaber-de dnaber-de added the bug label Mar 28, 2015

@dnaber-de dnaber-de changed the title from Iterator::offsetUnset() rewinds the iterator and causes recursion to Iterator::offsetUnset() rewinds the iterator and causes multiple iterations Mar 28, 2015

@dnaber-de dnaber-de closed this in 39fc6b5 Mar 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment