@@ -77,25 +77,6 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
77
77
}
78
78
/* }}} */
79
79
80
- /* Important: this overwrites the iterator data, if you wish to keep it use php_sxe_get_first_node_non_destructive() instead! */
81
- static xmlNodePtr php_sxe_get_first_node (php_sxe_object * sxe , xmlNodePtr node ) /* {{{ */
82
- {
83
- php_sxe_object * intern ;
84
- xmlNodePtr retnode = NULL ;
85
-
86
- if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
87
- php_sxe_reset_iterator (sxe , 1 );
88
- if (!Z_ISUNDEF (sxe -> iter .data )) {
89
- intern = Z_SXEOBJ_P (& sxe -> iter .data );
90
- GET_NODE (intern , retnode )
91
- }
92
- return retnode ;
93
- } else {
94
- return node ;
95
- }
96
- }
97
- /* }}} */
98
-
99
80
static xmlNodePtr php_sxe_get_first_node_non_destructive (php_sxe_object * sxe , xmlNodePtr node )
100
81
{
101
82
if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
@@ -182,7 +163,7 @@ static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node,
182
163
if (sxe -> iter .type == SXE_ITER_NONE ) {
183
164
sxe -> iter .type = SXE_ITER_CHILD ;
184
165
}
185
- node = php_sxe_get_first_node (sxe , node );
166
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
186
167
sxe -> iter .type = orgtype ;
187
168
}
188
169
@@ -257,11 +238,11 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
257
238
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
258
239
attribs = 1 ;
259
240
elements = 0 ;
260
- node = php_sxe_get_first_node (sxe , node );
241
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
261
242
attr = (xmlAttrPtr )node ;
262
243
test = sxe -> iter .name != NULL ;
263
244
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
264
- node = php_sxe_get_first_node (sxe , node );
245
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
265
246
attr = node ? node -> properties : NULL ;
266
247
test = 0 ;
267
248
if (!member && node && node -> parent &&
@@ -309,7 +290,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
309
290
xmlNodePtr mynode = node ;
310
291
311
292
if (sxe -> iter .type == SXE_ITER_CHILD ) {
312
- node = php_sxe_get_first_node (sxe , node );
293
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
313
294
}
314
295
if (sxe -> iter .type == SXE_ITER_NONE ) {
315
296
if (member && Z_LVAL_P (member ) > 0 ) {
@@ -445,12 +426,12 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
445
426
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
446
427
attribs = 1 ;
447
428
elements = 0 ;
448
- node = php_sxe_get_first_node (sxe , node );
429
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
449
430
attr = (xmlAttrPtr )node ;
450
431
test = sxe -> iter .name != NULL ;
451
432
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
452
433
mynode = node ;
453
- node = php_sxe_get_first_node (sxe , node );
434
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
454
435
attr = node ? node -> properties : NULL ;
455
436
test = 0 ;
456
437
if (!member && node && node -> parent &&
@@ -696,19 +677,19 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
696
677
attribs = 0 ;
697
678
elements = 1 ;
698
679
if (sxe -> iter .type == SXE_ITER_CHILD ) {
699
- node = php_sxe_get_first_node (sxe , node );
680
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
700
681
}
701
682
}
702
683
}
703
684
704
685
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
705
686
attribs = 1 ;
706
687
elements = 0 ;
707
- node = php_sxe_get_first_node (sxe , node );
688
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
708
689
attr = (xmlAttrPtr )node ;
709
690
test = sxe -> iter .name != NULL ;
710
691
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
711
- node = php_sxe_get_first_node (sxe , node );
692
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
712
693
attr = node ? node -> properties : NULL ;
713
694
test = 0 ;
714
695
}
@@ -748,7 +729,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
748
729
if (elements ) {
749
730
if (Z_TYPE_P (member ) == IS_LONG ) {
750
731
if (sxe -> iter .type == SXE_ITER_CHILD ) {
751
- node = php_sxe_get_first_node (sxe , node );
732
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
752
733
}
753
734
node = sxe_get_element_by_offset (sxe , Z_LVAL_P (member ), node , NULL );
754
735
} else {
@@ -820,19 +801,19 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
820
801
attribs = 0 ;
821
802
elements = 1 ;
822
803
if (sxe -> iter .type == SXE_ITER_CHILD ) {
823
- node = php_sxe_get_first_node (sxe , node );
804
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
824
805
}
825
806
}
826
807
}
827
808
828
809
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
829
810
attribs = 1 ;
830
811
elements = 0 ;
831
- node = php_sxe_get_first_node (sxe , node );
812
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
832
813
attr = (xmlAttrPtr )node ;
833
814
test = sxe -> iter .name != NULL ;
834
815
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
835
- node = php_sxe_get_first_node (sxe , node );
816
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
836
817
attr = node ? node -> properties : NULL ;
837
818
test = 0 ;
838
819
}
@@ -869,7 +850,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
869
850
if (elements ) {
870
851
if (Z_TYPE_P (member ) == IS_LONG ) {
871
852
if (sxe -> iter .type == SXE_ITER_CHILD ) {
872
- node = php_sxe_get_first_node (sxe , node );
853
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
873
854
}
874
855
node = sxe_get_element_by_offset (sxe , Z_LVAL_P (member ), node , NULL );
875
856
if (node ) {
@@ -1002,7 +983,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
1002
983
}
1003
984
1004
985
if (sxe -> iter .type == SXE_ITER_ELEMENT ) {
1005
- node = php_sxe_get_first_node (sxe , node );
986
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1006
987
}
1007
988
if (!node || node -> type != XML_ENTITY_DECL ) {
1008
989
attr = node ? (xmlAttrPtr )node -> properties : NULL ;
@@ -1016,7 +997,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
1016
997
}
1017
998
1018
999
GET_NODE (sxe , node );
1019
- node = php_sxe_get_first_node (sxe , node );
1000
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1020
1001
is_empty = 1 ;
1021
1002
ZVAL_UNDEF (& iter_data );
1022
1003
if (node && sxe -> iter .type != SXE_ITER_ATTRLIST ) {
@@ -1111,7 +1092,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
1111
1092
}
1112
1093
if (is_debug || sxe -> iter .type != SXE_ITER_CHILD ) {
1113
1094
if (sxe -> iter .type == SXE_ITER_ELEMENT ) {
1114
- node = php_sxe_get_first_node (sxe , node );
1095
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1115
1096
}
1116
1097
if (!node || node -> type != XML_ENTITY_DECL ) {
1117
1098
attr = node ? (xmlAttrPtr )node -> properties : NULL ;
@@ -1133,7 +1114,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
1133
1114
}
1134
1115
1135
1116
GET_NODE (sxe , node );
1136
- node = php_sxe_get_first_node (sxe , node );
1117
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1137
1118
1138
1119
if (node && sxe -> iter .type != SXE_ITER_ATTRLIST ) {
1139
1120
if (node -> type == XML_ATTRIBUTE_NODE ) {
@@ -1292,7 +1273,7 @@ PHP_METHOD(SimpleXMLElement, xpath)
1292
1273
}
1293
1274
1294
1275
GET_NODE (sxe , nodeptr );
1295
- nodeptr = php_sxe_get_first_node (sxe , nodeptr );
1276
+ nodeptr = php_sxe_get_first_node_non_destructive (sxe , nodeptr );
1296
1277
if (!nodeptr ) {
1297
1278
return ;
1298
1279
}
@@ -1401,7 +1382,7 @@ PHP_METHOD(SimpleXMLElement, asXML)
1401
1382
1402
1383
sxe = Z_SXEOBJ_P (ZEND_THIS );
1403
1384
GET_NODE (sxe , node );
1404
- node = php_sxe_get_first_node (sxe , node );
1385
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1405
1386
1406
1387
if (!node ) {
1407
1388
RETURN_FALSE ;
@@ -1524,7 +1505,7 @@ PHP_METHOD(SimpleXMLElement, getNamespaces)
1524
1505
1525
1506
sxe = Z_SXEOBJ_P (ZEND_THIS );
1526
1507
GET_NODE (sxe , node );
1527
- node = php_sxe_get_first_node (sxe , node );
1508
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1528
1509
1529
1510
if (node ) {
1530
1511
if (node -> type == XML_ELEMENT_NODE ) {
@@ -1609,7 +1590,7 @@ PHP_METHOD(SimpleXMLElement, children)
1609
1590
}
1610
1591
1611
1592
GET_NODE (sxe , node );
1612
- node = php_sxe_get_first_node (sxe , node );
1593
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1613
1594
if (!node ) {
1614
1595
return ;
1615
1596
}
@@ -1658,7 +1639,7 @@ PHP_METHOD(SimpleXMLElement, attributes)
1658
1639
1659
1640
sxe = Z_SXEOBJ_P (ZEND_THIS );
1660
1641
GET_NODE (sxe , node );
1661
- node = php_sxe_get_first_node (sxe , node );
1642
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1662
1643
if (!node ) {
1663
1644
return ;
1664
1645
}
@@ -1701,7 +1682,7 @@ PHP_METHOD(SimpleXMLElement, addChild)
1701
1682
return ;
1702
1683
}
1703
1684
1704
- node = php_sxe_get_first_node (sxe , node );
1685
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1705
1686
1706
1687
if (node == NULL ) {
1707
1688
php_error_docref (NULL , E_WARNING , "Cannot add child. Parent is not a permanent member of the XML tree" );
@@ -1761,7 +1742,7 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
1761
1742
sxe = Z_SXEOBJ_P (ZEND_THIS );
1762
1743
GET_NODE (sxe , node );
1763
1744
1764
- node = php_sxe_get_first_node (sxe , node );
1745
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1765
1746
1766
1747
if (node && node -> type != XML_ELEMENT_NODE ) {
1767
1748
node = node -> parent ;
@@ -2608,7 +2589,7 @@ void *simplexml_export_node(zval *object) /* {{{ */
2608
2589
2609
2590
sxe = Z_SXEOBJ_P (object );
2610
2591
GET_NODE (sxe , node );
2611
- return php_sxe_get_first_node (sxe , node );
2592
+ return php_sxe_get_first_node_non_destructive (sxe , node );
2612
2593
}
2613
2594
/* }}} */
2614
2595
0 commit comments