From efdaf53cf57766332407c0a3ae8b6e6d131e6a1e Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Thu, 14 May 2009 16:43:38 +0000 Subject: [PATCH] MFB: Fixed bug #45614 (ArrayIterator::current(), ::key() can show 1st private prop of wrapped object) --- ext/spl/spl_array.c | 12 ++++---- ext/spl/tests/bug45614.phpt | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 ext/spl/tests/bug45614.phpt diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 6030390213..08f391b956 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -82,6 +82,8 @@ static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int } } +static void spl_array_rewind(spl_array_object *intern TSRMLS_DC); + SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */ { HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); @@ -98,7 +100,7 @@ SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */ p = p->pListNext; } /* HASH_UNPROTECT_RECURSION(ht); */ - zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); + spl_array_rewind(intern TSRMLS_CC); return FAILURE; } /* }}} */ @@ -218,7 +220,7 @@ static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, s } } - zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); + spl_array_rewind(intern TSRMLS_CC); return retval; } /* }}} */ @@ -678,8 +680,6 @@ static int spl_array_has_property(zval *object, zval *member, int has_set_exists return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC); } /* }}} */ -static void spl_array_rewind(spl_array_object *intern TSRMLS_DC); - static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */ { spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); @@ -1126,7 +1126,7 @@ SPL_METHOD(Array, seek) opos = position; if (position >= 0) { /* negative values are not supported */ - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); + spl_array_rewind(intern TSRMLS_CC); result = SUCCESS; while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS); @@ -1155,7 +1155,7 @@ int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ * we're going to call and which do not support 'pos' as parameter. */ pos = intern->pos; *count = 0; - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); + spl_array_rewind(intern TSRMLS_CC); while(intern->pos && spl_array_next(intern TSRMLS_CC) == SUCCESS) { (*count)++; } diff --git a/ext/spl/tests/bug45614.phpt b/ext/spl/tests/bug45614.phpt new file mode 100644 index 0000000000..8f999348e8 --- /dev/null +++ b/ext/spl/tests/bug45614.phpt @@ -0,0 +1,56 @@ +--TEST-- +SPL: Bug#45614 (ArrayIterator can show 1st private prop of wrapped object) +--FILE-- +key()) . " => " . $it->current() . +"\n"; + $it->next(); + echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() . +"\n"; +} + +$ao = new ArrayObject(new C); +$ai = $ao->getIterator(); + +echo "--> Show the first two items:\n"; +showFirstTwoItems($ai); + +echo "\n--> Rewind and show the first two items:\n"; +$ai->rewind(); +showFirstTwoItems($ai); + +echo "\n--> Invalidate current position and show the first two items:\n"; +unset($ai[$ai->key()]); +$ai->current(); +showFirstTwoItems($ai); + +echo "\n--> Rewind, seek and show the first two items:\n"; +$ai->rewind(); +$ai->seek(0); +showFirstTwoItems($ai); +?> +--EXPECT-- +--> Show the first two items: +pub1 => public1 +pub2 => public2 + +--> Rewind and show the first two items: +pub1 => public1 +pub2 => public2 + +--> Invalidate current position and show the first two items: +pub1 => public1 +pub3 => public3 + +--> Rewind, seek and show the first two items: +pub1 => public1 +pub3 => public3 -- 2.50.1