From: Etienne Kneuss Date: Thu, 15 May 2008 17:22:03 +0000 (+0000) Subject: Replace the iterator correctly after being cloned (related to #44964) X-Git-Tag: BEFORE_HEAD_NS_CHANGE~1753 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2593307f3469be18462492ebc67e533ac7b17bc;p=php Replace the iterator correctly after being cloned (related to #44964) --- diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index a96a1a3169..e44a0fe985 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -298,6 +298,7 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC) zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); spl_filesystem_object *intern; spl_filesystem_object *source; + int index; old_object = zend_objects_get_address(zobject TSRMLS_CC); source = (spl_filesystem_object*)old_object; @@ -316,6 +317,11 @@ static zend_object_value spl_filesystem_object_clone(zval *zobject TSRMLS_DC) break; case SPL_FS_DIR: spl_filesystem_dir_open(intern, source->_path_type, source->_path, source->_path_len TSRMLS_CC); + /* read until we hit the position in which we were before */ + for(index = 0; index < source->u.dir.index; ++index) { + spl_filesystem_dir_read(intern TSRMLS_CC); + } + intern->u.dir.index = index; break; case SPL_FS_FILE: php_error_docref(NULL TSRMLS_CC, E_ERROR, "An object of class %v cannot be cloned", old_object->ce->name);