- Fix count/foreach interaction

This commit is contained in:
Marcus Boerger 2006-02-27 13:32:25 +00:00
parent d8b7f1dea0
commit 10a5901abf
3 changed files with 60 additions and 1 deletions

View File

@ -67,7 +67,6 @@ typedef struct {
HashTable *properties;
xmlXPathContextPtr xpath;
struct {
int itertype;
char *name;
char *nsprefix;
SXE_ITER type;

View File

@ -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;
}

51
ext/simplexml/tests/029.phpt Executable file
View File

@ -0,0 +1,51 @@
--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===
--UEXPECTF--
unicode(3) "Joe"
int(3)
int(0)
unicode(4) "John"
int(3)
int(1)
unicode(4) "Jane"
int(3)
int(0)
===DONE===