diff options
| author | Andrew Curioso <acurioso@php.net> | 2011-05-18 04:43:21 +0000 |
|---|---|---|
| committer | Andrew Curioso <acurioso@php.net> | 2011-05-18 04:43:21 +0000 |
| commit | 1e3b32c777829f61fa9a18278e0647e9112d96ea (patch) | |
| tree | 78a8fa053895a056a0b6f2db75e4740c01939488 /ext | |
| parent | cfdd25d5c00fc2b587497b664489e4125895a522 (diff) | |
| download | php-git-1e3b32c777829f61fa9a18278e0647e9112d96ea.tar.gz | |
Commiting r311138 into the 5.3 branch - fix to SimpleXML get properties hash
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/simplexml/simplexml.c | 36 | ||||
| -rwxr-xr-x | ext/simplexml/tests/034.phpt | 6 | ||||
| -rw-r--r-- | ext/simplexml/tests/bug51615.phpt | 4 |
3 files changed, 39 insertions, 7 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index f9504fe58d..98dbc0c13e 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1069,6 +1069,10 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{ xmlAttrPtr attr; int namelen; int test; + char use_iter; + zval *iter_data; + + use_iter = 0; sxe = php_sxe_fetch_object(object TSRMLS_CC); @@ -1122,6 +1126,7 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{ GET_NODE(sxe, node); node = php_sxe_get_first_node(sxe, node TSRMLS_CC); + if (node && sxe->iter.type != SXE_ITER_ATTRLIST) { if (node->type == XML_ATTRIBUTE_NODE) { MAKE_STD_ZVAL(value); @@ -1129,7 +1134,17 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{ zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL); node = NULL; } else if (sxe->iter.type != SXE_ITER_CHILD) { - node = node->children; + + if ( !node->children || !node->parent || node->children->next || node->children->children || node->parent->children == node->parent->last ) { + node = node->children; + } else { + iter_data = sxe->iter.data; + sxe->iter.data = NULL; + + node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC); + + use_iter = 1; + } } while (node) { @@ -1161,10 +1176,25 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{ _get_base_node_value(sxe, node, &value, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC); - sxe_properties_add(rv, name, namelen, value TSRMLS_CC); + if ( use_iter ) { + zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL); + } else { + sxe_properties_add(rv, name, namelen, value TSRMLS_CC); + } next_iter: - node = node->next; + if ( use_iter ) { + node = php_sxe_iterator_fetch(sxe, node->next, 0 TSRMLS_CC); + } else { + node = node->next; + } + } + } + + if ( use_iter ) { + if (sxe->iter.data) { + zval_ptr_dtor(&sxe->iter.data); } + sxe->iter.data = iter_data; } return rv; diff --git a/ext/simplexml/tests/034.phpt b/ext/simplexml/tests/034.phpt index 1f3a854fde..8610f70367 100755 --- a/ext/simplexml/tests/034.phpt +++ b/ext/simplexml/tests/034.phpt @@ -1,7 +1,7 @@ --TEST-- -SimpleXML: array casting bug ---XFAIL-- -Does anyone know why? +SimpleXML: cast to array +--FAIL-- +Length of cast array does not match expected length --SKIPIF-- <?php if (!extension_loaded("simplexml")) print "skip"; ?> --FILE-- diff --git a/ext/simplexml/tests/bug51615.phpt b/ext/simplexml/tests/bug51615.phpt index 75f6769ff7..e022994313 100644 --- a/ext/simplexml/tests/bug51615.phpt +++ b/ext/simplexml/tests/bug51615.phpt @@ -20,7 +20,7 @@ foreach ($html->body->span as $obj) { Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d -object(SimpleXMLElement)#%d (2) { +object(SimpleXMLElement)#%d (3) { ["@attributes"]=> array(2) { ["title"]=> @@ -30,6 +30,8 @@ object(SimpleXMLElement)#%d (2) { } [0]=> string(1) "x" + [1]=> + string(1) "x" } string(0) "" string(0) "" |
