Skip to content

Commit ec2ef64

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Apply SimpleXML iterator fixes only on master
2 parents 7efc531 + 77f44b2 commit ec2ef64

File tree

6 files changed

+36
-188
lines changed

6 files changed

+36
-188
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ PHP NEWS
1717
. Fixed bug GH-12297 (PHP Startup: Invalid library (maybe not a PHP library)
1818
'mysqlnd.so' in Unknown on line). (nielsdos)
1919

20+
- SimpleXML:
21+
. Apply iterator fixes only on master. (nielsdos)
22+
2023
- XSL:
2124
. Fix type error on XSLTProcessor::transformToDoc return value with
2225
SimpleXML. (nielsdos)

ext/simplexml/simplexml.c

+31-31
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
7777
}
7878
/* }}} */
7979

80-
static xmlNodePtr php_sxe_get_first_node_non_destructive(php_sxe_object *sxe, xmlNodePtr node)
80+
static xmlNodePtr php_sxe_get_first_node(php_sxe_object *sxe, xmlNodePtr node)
8181
{
8282
if (sxe && sxe->iter.type != SXE_ITER_NONE) {
83-
return php_sxe_reset_iterator_no_clear_iter_data(sxe, false);
83+
return php_sxe_reset_iterator(sxe, 1);
8484
} else {
8585
return node;
8686
}
@@ -163,7 +163,7 @@ static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node,
163163
if (sxe->iter.type == SXE_ITER_NONE) {
164164
sxe->iter.type = SXE_ITER_CHILD;
165165
}
166-
node = php_sxe_get_first_node_non_destructive(sxe, node);
166+
node = php_sxe_get_first_node(sxe, node);
167167
sxe->iter.type = orgtype;
168168
}
169169

@@ -238,11 +238,11 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
238238
if (sxe->iter.type == SXE_ITER_ATTRLIST) {
239239
attribs = 1;
240240
elements = 0;
241-
node = php_sxe_get_first_node_non_destructive(sxe, node);
241+
node = php_sxe_get_first_node(sxe, node);
242242
attr = (xmlAttrPtr)node;
243243
test = sxe->iter.name != NULL;
244244
} else if (sxe->iter.type != SXE_ITER_CHILD) {
245-
node = php_sxe_get_first_node_non_destructive(sxe, node);
245+
node = php_sxe_get_first_node(sxe, node);
246246
attr = node ? node->properties : NULL;
247247
test = 0;
248248
if (!member && node && node->parent &&
@@ -290,7 +290,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
290290
xmlNodePtr mynode = node;
291291

292292
if (sxe->iter.type == SXE_ITER_CHILD) {
293-
node = php_sxe_get_first_node_non_destructive(sxe, node);
293+
node = php_sxe_get_first_node(sxe, node);
294294
}
295295
if (sxe->iter.type == SXE_ITER_NONE) {
296296
if (member && Z_LVAL_P(member) > 0) {
@@ -426,12 +426,12 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
426426
if (sxe->iter.type == SXE_ITER_ATTRLIST) {
427427
attribs = 1;
428428
elements = 0;
429-
node = php_sxe_get_first_node_non_destructive(sxe, node);
429+
node = php_sxe_get_first_node(sxe, node);
430430
attr = (xmlAttrPtr)node;
431431
test = sxe->iter.name != NULL;
432432
} else if (sxe->iter.type != SXE_ITER_CHILD) {
433433
mynode = node;
434-
node = php_sxe_get_first_node_non_destructive(sxe, node);
434+
node = php_sxe_get_first_node(sxe, node);
435435
attr = node ? node->properties : NULL;
436436
test = 0;
437437
if (!member && node && node->parent &&
@@ -677,19 +677,19 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
677677
attribs = 0;
678678
elements = 1;
679679
if (sxe->iter.type == SXE_ITER_CHILD) {
680-
node = php_sxe_get_first_node_non_destructive(sxe, node);
680+
node = php_sxe_get_first_node(sxe, node);
681681
}
682682
}
683683
}
684684

685685
if (sxe->iter.type == SXE_ITER_ATTRLIST) {
686686
attribs = 1;
687687
elements = 0;
688-
node = php_sxe_get_first_node_non_destructive(sxe, node);
688+
node = php_sxe_get_first_node(sxe, node);
689689
attr = (xmlAttrPtr)node;
690690
test = sxe->iter.name != NULL;
691691
} else if (sxe->iter.type != SXE_ITER_CHILD) {
692-
node = php_sxe_get_first_node_non_destructive(sxe, node);
692+
node = php_sxe_get_first_node(sxe, node);
693693
attr = node ? node->properties : NULL;
694694
test = 0;
695695
}
@@ -729,7 +729,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
729729
if (elements) {
730730
if (Z_TYPE_P(member) == IS_LONG) {
731731
if (sxe->iter.type == SXE_ITER_CHILD) {
732-
node = php_sxe_get_first_node_non_destructive(sxe, node);
732+
node = php_sxe_get_first_node(sxe, node);
733733
}
734734
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL);
735735
} else {
@@ -801,19 +801,19 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
801801
attribs = 0;
802802
elements = 1;
803803
if (sxe->iter.type == SXE_ITER_CHILD) {
804-
node = php_sxe_get_first_node_non_destructive(sxe, node);
804+
node = php_sxe_get_first_node(sxe, node);
805805
}
806806
}
807807
}
808808

809809
if (sxe->iter.type == SXE_ITER_ATTRLIST) {
810810
attribs = 1;
811811
elements = 0;
812-
node = php_sxe_get_first_node_non_destructive(sxe, node);
812+
node = php_sxe_get_first_node(sxe, node);
813813
attr = (xmlAttrPtr)node;
814814
test = sxe->iter.name != NULL;
815815
} else if (sxe->iter.type != SXE_ITER_CHILD) {
816-
node = php_sxe_get_first_node_non_destructive(sxe, node);
816+
node = php_sxe_get_first_node(sxe, node);
817817
attr = node ? node->properties : NULL;
818818
test = 0;
819819
}
@@ -850,7 +850,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
850850
if (elements) {
851851
if (Z_TYPE_P(member) == IS_LONG) {
852852
if (sxe->iter.type == SXE_ITER_CHILD) {
853-
node = php_sxe_get_first_node_non_destructive(sxe, node);
853+
node = php_sxe_get_first_node(sxe, node);
854854
}
855855
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL);
856856
if (node) {
@@ -983,7 +983,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
983983
}
984984

985985
if (sxe->iter.type == SXE_ITER_ELEMENT) {
986-
node = php_sxe_get_first_node_non_destructive(sxe, node);
986+
node = php_sxe_get_first_node(sxe, node);
987987
}
988988
if (!node || node->type != XML_ENTITY_DECL) {
989989
attr = node ? (xmlAttrPtr)node->properties : NULL;
@@ -997,7 +997,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
997997
}
998998

999999
GET_NODE(sxe, node);
1000-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1000+
node = php_sxe_get_first_node(sxe, node);
10011001
is_empty = 1;
10021002
ZVAL_UNDEF(&iter_data);
10031003
if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
@@ -1092,7 +1092,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
10921092
}
10931093
if (is_debug || sxe->iter.type != SXE_ITER_CHILD) {
10941094
if (sxe->iter.type == SXE_ITER_ELEMENT) {
1095-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1095+
node = php_sxe_get_first_node(sxe, node);
10961096
}
10971097
if (!node || node->type != XML_ENTITY_DECL) {
10981098
attr = node ? (xmlAttrPtr)node->properties : NULL;
@@ -1114,7 +1114,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
11141114
}
11151115

11161116
GET_NODE(sxe, node);
1117-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1117+
node = php_sxe_get_first_node(sxe, node);
11181118

11191119
if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
11201120
if (node->type == XML_ATTRIBUTE_NODE) {
@@ -1273,7 +1273,7 @@ PHP_METHOD(SimpleXMLElement, xpath)
12731273
}
12741274

12751275
GET_NODE(sxe, nodeptr);
1276-
nodeptr = php_sxe_get_first_node_non_destructive(sxe, nodeptr);
1276+
nodeptr = php_sxe_get_first_node(sxe, nodeptr);
12771277
if (!nodeptr) {
12781278
return;
12791279
}
@@ -1382,7 +1382,7 @@ PHP_METHOD(SimpleXMLElement, asXML)
13821382

13831383
sxe = Z_SXEOBJ_P(ZEND_THIS);
13841384
GET_NODE(sxe, node);
1385-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1385+
node = php_sxe_get_first_node(sxe, node);
13861386

13871387
if (!node) {
13881388
RETURN_FALSE;
@@ -1505,7 +1505,7 @@ PHP_METHOD(SimpleXMLElement, getNamespaces)
15051505

15061506
sxe = Z_SXEOBJ_P(ZEND_THIS);
15071507
GET_NODE(sxe, node);
1508-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1508+
node = php_sxe_get_first_node(sxe, node);
15091509

15101510
if (node) {
15111511
if (node->type == XML_ELEMENT_NODE) {
@@ -1590,7 +1590,7 @@ PHP_METHOD(SimpleXMLElement, children)
15901590
}
15911591

15921592
GET_NODE(sxe, node);
1593-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1593+
node = php_sxe_get_first_node(sxe, node);
15941594
if (!node) {
15951595
return;
15961596
}
@@ -1614,7 +1614,7 @@ PHP_METHOD(SimpleXMLElement, getName)
16141614
sxe = Z_SXEOBJ_P(ZEND_THIS);
16151615

16161616
GET_NODE(sxe, node);
1617-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1617+
node = php_sxe_get_first_node(sxe, node);
16181618
if (node) {
16191619
namelen = xmlStrlen(node->name);
16201620
RETURN_STRINGL((char*)node->name, namelen);
@@ -1639,7 +1639,7 @@ PHP_METHOD(SimpleXMLElement, attributes)
16391639

16401640
sxe = Z_SXEOBJ_P(ZEND_THIS);
16411641
GET_NODE(sxe, node);
1642-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1642+
node = php_sxe_get_first_node(sxe, node);
16431643
if (!node) {
16441644
return;
16451645
}
@@ -1682,7 +1682,7 @@ PHP_METHOD(SimpleXMLElement, addChild)
16821682
return;
16831683
}
16841684

1685-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1685+
node = php_sxe_get_first_node(sxe, node);
16861686

16871687
if (node == NULL) {
16881688
php_error_docref(NULL, E_WARNING, "Cannot add child. Parent is not a permanent member of the XML tree");
@@ -1742,7 +1742,7 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
17421742
sxe = Z_SXEOBJ_P(ZEND_THIS);
17431743
GET_NODE(sxe, node);
17441744

1745-
node = php_sxe_get_first_node_non_destructive(sxe, node);
1745+
node = php_sxe_get_first_node(sxe, node);
17461746

17471747
if (node && node->type != XML_ELEMENT_NODE) {
17481748
node = node->parent;
@@ -1835,7 +1835,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18351835
sxe = php_sxe_fetch_object(readobj);
18361836

18371837
if (type == _IS_BOOL) {
1838-
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
1838+
node = php_sxe_get_first_node(sxe, NULL);
18391839
if (node) {
18401840
ZVAL_TRUE(writeobj);
18411841
} else {
@@ -1845,7 +1845,7 @@ static zend_result sxe_object_cast_ex(zend_object *readobj, zval *writeobj, int
18451845
}
18461846

18471847
if (sxe->iter.type != SXE_ITER_NONE) {
1848-
node = php_sxe_get_first_node_non_destructive(sxe, NULL);
1848+
node = php_sxe_get_first_node(sxe, NULL);
18491849
if (node) {
18501850
contents = xmlNodeListGetString((xmlDocPtr) sxe->document->ptr, node->children, 1);
18511851
}
@@ -2593,7 +2593,7 @@ void *simplexml_export_node(zval *object) /* {{{ */
25932593

25942594
sxe = Z_SXEOBJ_P(object);
25952595
GET_NODE(sxe, node);
2596-
return php_sxe_get_first_node_non_destructive(sxe, node);
2596+
return php_sxe_get_first_node(sxe, node);
25972597
}
25982598
/* }}} */
25992599

ext/simplexml/tests/bug55098.phpt

-92
This file was deleted.

ext/simplexml/tests/bug62639.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ foreach ($a2->b->c->children() as $key => $value) {
4141
var_dump($value);
4242
}?>
4343
--EXPECT--
44-
object(A)#4 (2) {
44+
object(A)#2 (2) {
4545
["@attributes"]=>
4646
array(1) {
4747
["attr"]=>
@@ -50,7 +50,7 @@ object(A)#4 (2) {
5050
[0]=>
5151
string(10) "Some Value"
5252
}
53-
object(A)#6 (2) {
53+
object(A)#3 (2) {
5454
["@attributes"]=>
5555
array(1) {
5656
["attr"]=>

0 commit comments

Comments
 (0)