Skip to content

Commit 1e3b32c

Browse files
committed
Commiting r311138 into the 5.3 branch - fix to SimpleXML get properties hash
1 parent cfdd25d commit 1e3b32c

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ UPGRADE NOTES - PHP X.Y
170170
- fclose() closes streams with resource refcount > 1; it doesn't merely
171171
decrement the resource refcount.
172172
- socket_set_options() and socket_get_options() now support multicast options.
173+
- Arrays cast from SimpleXMLElement now always contain all nodes instead of
174+
just the first matching node.
175+
- All SimpleXMLElement children are now always printed when using var_dump(),
176+
var_export(), and print_r().
173177

174178
===================================
175179
5. Changes made to existing methods

ext/simplexml/simplexml.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,10 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
10691069
xmlAttrPtr attr;
10701070
int namelen;
10711071
int test;
1072+
char use_iter;
1073+
zval *iter_data;
1074+
1075+
use_iter = 0;
10721076

10731077
sxe = php_sxe_fetch_object(object TSRMLS_CC);
10741078

@@ -1122,14 +1126,25 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
11221126

11231127
GET_NODE(sxe, node);
11241128
node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
1129+
11251130
if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
11261131
if (node->type == XML_ATTRIBUTE_NODE) {
11271132
MAKE_STD_ZVAL(value);
11281133
ZVAL_STRING(value, sxe_xmlNodeListGetString(node->doc, node->children, 1), 0);
11291134
zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
11301135
node = NULL;
11311136
} else if (sxe->iter.type != SXE_ITER_CHILD) {
1132-
node = node->children;
1137+
1138+
if ( !node->children || !node->parent || node->children->next || node->children->children || node->parent->children == node->parent->last ) {
1139+
node = node->children;
1140+
} else {
1141+
iter_data = sxe->iter.data;
1142+
sxe->iter.data = NULL;
1143+
1144+
node = php_sxe_reset_iterator(sxe, 0 TSRMLS_CC);
1145+
1146+
use_iter = 1;
1147+
}
11331148
}
11341149

11351150
while (node) {
@@ -1161,10 +1176,25 @@ static HashTable * sxe_get_prop_hash(zval *object, int is_debug TSRMLS_DC) /* {{
11611176

11621177
_get_base_node_value(sxe, node, &value, sxe->iter.nsprefix, sxe->iter.isprefix TSRMLS_CC);
11631178

1164-
sxe_properties_add(rv, name, namelen, value TSRMLS_CC);
1179+
if ( use_iter ) {
1180+
zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
1181+
} else {
1182+
sxe_properties_add(rv, name, namelen, value TSRMLS_CC);
1183+
}
11651184
next_iter:
1166-
node = node->next;
1185+
if ( use_iter ) {
1186+
node = php_sxe_iterator_fetch(sxe, node->next, 0 TSRMLS_CC);
1187+
} else {
1188+
node = node->next;
1189+
}
1190+
}
1191+
}
1192+
1193+
if ( use_iter ) {
1194+
if (sxe->iter.data) {
1195+
zval_ptr_dtor(&sxe->iter.data);
11671196
}
1197+
sxe->iter.data = iter_data;
11681198
}
11691199

11701200
return rv;

ext/simplexml/tests/034.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--TEST--
2-
SimpleXML: array casting bug
3-
--XFAIL--
4-
Does anyone know why?
2+
SimpleXML: cast to array
3+
--FAIL--
4+
Length of cast array does not match expected length
55
--SKIPIF--
66
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
77
--FILE--

ext/simplexml/tests/bug51615.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ foreach ($html->body->span as $obj) {
2020
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
2121

2222
Warning: DOMDocument::loadHTML(): error parsing attribute name in Entity, line: 1 in %s on line %d
23-
object(SimpleXMLElement)#%d (2) {
23+
object(SimpleXMLElement)#%d (3) {
2424
["@attributes"]=>
2525
array(2) {
2626
["title"]=>
@@ -30,6 +30,8 @@ object(SimpleXMLElement)#%d (2) {
3030
}
3131
[0]=>
3232
string(1) "x"
33+
[1]=>
34+
string(1) "x"
3335
}
3436
string(0) ""
3537
string(0) ""

0 commit comments

Comments
 (0)