From: Marcus Boerger Date: Mon, 27 Feb 2006 13:32:25 +0000 (+0000) Subject: - Fix count/foreach interaction X-Git-Tag: RELEASE_1_2~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10a5901abf1d11499994e211f6d605ac5ccda055;p=php - Fix count/foreach interaction --- diff --git a/ext/simplexml/php_simplexml.h b/ext/simplexml/php_simplexml.h index 0b3b0860d4..5af5e67245 100644 --- a/ext/simplexml/php_simplexml.h +++ b/ext/simplexml/php_simplexml.h @@ -67,7 +67,6 @@ typedef struct { HashTable *properties; xmlXPathContextPtr xpath; struct { - int itertype; char *name; char *nsprefix; SXE_ITER type; diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 25dd25bd3b..5e287aa900 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1438,9 +1438,14 @@ static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */ { php_sxe_object *sxe; xmlNodePtr node; + zval *data; *count = 0; sxe = php_sxe_fetch_object(object TSRMLS_CC); + + data = sxe->iter.data; + sxe->iter.data = NULL; + node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC); while (node) @@ -1449,6 +1454,10 @@ static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */ node = php_sxe_iterator_fetch(sxe, node->next, 0 TSRMLS_CC); } + if (sxe->iter.data) { + zval_ptr_dtor(&sxe->iter.data); + } + sxe->iter.data = data; return SUCCESS; } diff --git a/ext/simplexml/tests/029.phpt b/ext/simplexml/tests/029.phpt new file mode 100755 index 0000000000..1624b12d50 --- /dev/null +++ b/ext/simplexml/tests/029.phpt @@ -0,0 +1,51 @@ +--TEST-- +SimpleXML: foreach and count +--SKIPIF-- + +--FILE-- + + + + + + + + + +EOF; + +$people = simplexml_load_string($xml); + +foreach($people as $person) +{ + var_dump((string)$person['name']); + var_dump(count($people)); + var_dump(count($person)); +} + +?> +===DONE=== +--EXPECTF-- +string(3) "Joe" +int(3) +int(0) +string(4) "John" +int(3) +int(1) +string(4) "Jane" +int(3) +int(0) +===DONE=== +--UEXPECTF-- +unicode(3) "Joe" +int(3) +int(0) +unicode(4) "John" +int(3) +int(1) +unicode(4) "Jane" +int(3) +int(0) +===DONE===