diff options
-rw-r--r-- | ext/simplexml/simplexml.c | 10 | ||||
-rwxr-xr-x | ext/simplexml/tests/029.phpt | 40 |
2 files changed, 50 insertions, 0 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 05b7f11c9b..e8150eaf98 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) @@ -1450,6 +1455,11 @@ static int sxe_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */ } + 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..86a4f308e3 --- /dev/null +++ b/ext/simplexml/tests/029.phpt @@ -0,0 +1,40 @@ +--TEST-- +SimpleXML: foreach and count +--SKIPIF-- +<?php if (!extension_loaded("simplexml")) print "skip"; ?> +--FILE-- +<?php +$xml =<<<EOF +<people> + <person name="Joe"/> + <person name="John"> + <children> + <person name="Joe"/> + </children> + </person> + <person name="Jane"/> +</people> +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=== |