@@ -77,17 +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
- if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
84
- return php_sxe_reset_iterator (sxe , 1 );
85
- } else {
86
- return node ;
87
- }
88
- }
89
- /* }}} */
90
-
91
80
static xmlNodePtr php_sxe_get_first_node_non_destructive (php_sxe_object * sxe , xmlNodePtr node )
92
81
{
93
82
if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
@@ -170,7 +159,7 @@ static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node,
170
159
if (sxe -> iter .type == SXE_ITER_NONE ) {
171
160
sxe -> iter .type = SXE_ITER_CHILD ;
172
161
}
173
- node = php_sxe_get_first_node (sxe , node );
162
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
174
163
sxe -> iter .type = orgtype ;
175
164
}
176
165
@@ -243,11 +232,11 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
243
232
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
244
233
attribs = 1 ;
245
234
elements = 0 ;
246
- node = php_sxe_get_first_node (sxe , node );
235
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
247
236
attr = (xmlAttrPtr )node ;
248
237
test = sxe -> iter .name != NULL ;
249
238
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
250
- node = php_sxe_get_first_node (sxe , node );
239
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
251
240
attr = node ? node -> properties : NULL ;
252
241
test = 0 ;
253
242
if (!member && node && node -> parent &&
@@ -295,7 +284,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
295
284
xmlNodePtr mynode = node ;
296
285
297
286
if (sxe -> iter .type == SXE_ITER_CHILD ) {
298
- node = php_sxe_get_first_node (sxe , node );
287
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
299
288
}
300
289
if (sxe -> iter .type == SXE_ITER_NONE ) {
301
290
if (member && Z_LVAL_P (member ) > 0 ) {
@@ -431,12 +420,12 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
431
420
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
432
421
attribs = 1 ;
433
422
elements = 0 ;
434
- node = php_sxe_get_first_node (sxe , node );
423
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
435
424
attr = (xmlAttrPtr )node ;
436
425
test = sxe -> iter .name != NULL ;
437
426
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
438
427
mynode = node ;
439
- node = php_sxe_get_first_node (sxe , node );
428
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
440
429
attr = node ? node -> properties : NULL ;
441
430
test = 0 ;
442
431
if (!member && node && node -> parent &&
@@ -682,19 +671,19 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
682
671
attribs = 0 ;
683
672
elements = 1 ;
684
673
if (sxe -> iter .type == SXE_ITER_CHILD ) {
685
- node = php_sxe_get_first_node (sxe , node );
674
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
686
675
}
687
676
}
688
677
}
689
678
690
679
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
691
680
attribs = 1 ;
692
681
elements = 0 ;
693
- node = php_sxe_get_first_node (sxe , node );
682
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
694
683
attr = (xmlAttrPtr )node ;
695
684
test = sxe -> iter .name != NULL ;
696
685
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
697
- node = php_sxe_get_first_node (sxe , node );
686
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
698
687
attr = node ? node -> properties : NULL ;
699
688
test = 0 ;
700
689
}
@@ -734,7 +723,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
734
723
if (elements ) {
735
724
if (Z_TYPE_P (member ) == IS_LONG ) {
736
725
if (sxe -> iter .type == SXE_ITER_CHILD ) {
737
- node = php_sxe_get_first_node (sxe , node );
726
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
738
727
}
739
728
node = sxe_get_element_by_offset (sxe , Z_LVAL_P (member ), node , NULL );
740
729
} else {
@@ -806,19 +795,19 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
806
795
attribs = 0 ;
807
796
elements = 1 ;
808
797
if (sxe -> iter .type == SXE_ITER_CHILD ) {
809
- node = php_sxe_get_first_node (sxe , node );
798
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
810
799
}
811
800
}
812
801
}
813
802
814
803
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
815
804
attribs = 1 ;
816
805
elements = 0 ;
817
- node = php_sxe_get_first_node (sxe , node );
806
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
818
807
attr = (xmlAttrPtr )node ;
819
808
test = sxe -> iter .name != NULL ;
820
809
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
821
- node = php_sxe_get_first_node (sxe , node );
810
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
822
811
attr = node ? node -> properties : NULL ;
823
812
test = 0 ;
824
813
}
@@ -855,7 +844,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
855
844
if (elements ) {
856
845
if (Z_TYPE_P (member ) == IS_LONG ) {
857
846
if (sxe -> iter .type == SXE_ITER_CHILD ) {
858
- node = php_sxe_get_first_node (sxe , node );
847
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
859
848
}
860
849
node = sxe_get_element_by_offset (sxe , Z_LVAL_P (member ), node , NULL );
861
850
if (node ) {
@@ -987,7 +976,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
987
976
}
988
977
989
978
if (sxe -> iter .type == SXE_ITER_ELEMENT ) {
990
- node = php_sxe_get_first_node (sxe , node );
979
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
991
980
}
992
981
if (node && node -> type != XML_ENTITY_DECL ) {
993
982
attr = node -> properties ;
@@ -1001,7 +990,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
1001
990
}
1002
991
1003
992
GET_NODE (sxe , node );
1004
- node = php_sxe_get_first_node (sxe , node );
993
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1005
994
is_empty = 1 ;
1006
995
if (node && sxe -> iter .type != SXE_ITER_ATTRLIST ) {
1007
996
if (node -> type == XML_ATTRIBUTE_NODE ) {
@@ -1083,7 +1072,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
1083
1072
}
1084
1073
if (is_debug || sxe -> iter .type != SXE_ITER_CHILD ) {
1085
1074
if (sxe -> iter .type == SXE_ITER_ELEMENT ) {
1086
- node = php_sxe_get_first_node (sxe , node );
1075
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1087
1076
}
1088
1077
if (node && node -> type != XML_ENTITY_DECL ) {
1089
1078
attr = node -> properties ;
@@ -1105,7 +1094,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
1105
1094
}
1106
1095
1107
1096
GET_NODE (sxe , node );
1108
- node = php_sxe_get_first_node (sxe , node );
1097
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1109
1098
1110
1099
if (node && sxe -> iter .type != SXE_ITER_ATTRLIST ) {
1111
1100
if (node -> type == XML_ATTRIBUTE_NODE ) {
@@ -1252,7 +1241,7 @@ PHP_METHOD(SimpleXMLElement, xpath)
1252
1241
}
1253
1242
1254
1243
GET_NODE (sxe , nodeptr );
1255
- nodeptr = php_sxe_get_first_node (sxe , nodeptr );
1244
+ nodeptr = php_sxe_get_first_node_non_destructive (sxe , nodeptr );
1256
1245
if (!nodeptr ) {
1257
1246
return ;
1258
1247
}
@@ -1362,7 +1351,7 @@ PHP_METHOD(SimpleXMLElement, asXML)
1362
1351
1363
1352
sxe = Z_SXEOBJ_P (ZEND_THIS );
1364
1353
GET_NODE (sxe , node );
1365
- node = php_sxe_get_first_node (sxe , node );
1354
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1366
1355
1367
1356
if (!node ) {
1368
1357
RETURN_FALSE ;
@@ -1480,7 +1469,7 @@ PHP_METHOD(SimpleXMLElement, getNamespaces)
1480
1469
1481
1470
sxe = Z_SXEOBJ_P (ZEND_THIS );
1482
1471
GET_NODE (sxe , node );
1483
- node = php_sxe_get_first_node (sxe , node );
1472
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1484
1473
1485
1474
if (node ) {
1486
1475
if (node -> type == XML_ELEMENT_NODE ) {
@@ -1565,7 +1554,7 @@ PHP_METHOD(SimpleXMLElement, children)
1565
1554
}
1566
1555
1567
1556
GET_NODE (sxe , node );
1568
- node = php_sxe_get_first_node (sxe , node );
1557
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1569
1558
if (!node ) {
1570
1559
return ;
1571
1560
}
@@ -1614,7 +1603,7 @@ PHP_METHOD(SimpleXMLElement, attributes)
1614
1603
1615
1604
sxe = Z_SXEOBJ_P (ZEND_THIS );
1616
1605
GET_NODE (sxe , node );
1617
- node = php_sxe_get_first_node (sxe , node );
1606
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1618
1607
if (!node ) {
1619
1608
return ;
1620
1609
}
@@ -1657,7 +1646,7 @@ PHP_METHOD(SimpleXMLElement, addChild)
1657
1646
return ;
1658
1647
}
1659
1648
1660
- node = php_sxe_get_first_node (sxe , node );
1649
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1661
1650
1662
1651
if (node == NULL ) {
1663
1652
php_error_docref (NULL , E_WARNING , "Cannot add child. Parent is not a permanent member of the XML tree" );
@@ -1717,7 +1706,7 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
1717
1706
sxe = Z_SXEOBJ_P (ZEND_THIS );
1718
1707
GET_NODE (sxe , node );
1719
1708
1720
- node = php_sxe_get_first_node (sxe , node );
1709
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1721
1710
1722
1711
if (node && node -> type != XML_ELEMENT_NODE ) {
1723
1712
node = node -> parent ;
@@ -2550,7 +2539,7 @@ void *simplexml_export_node(zval *object) /* {{{ */
2550
2539
2551
2540
sxe = Z_SXEOBJ_P (object );
2552
2541
GET_NODE (sxe , node );
2553
- return php_sxe_get_first_node (sxe , node );
2542
+ return php_sxe_get_first_node_non_destructive (sxe , node );
2554
2543
}
2555
2544
/* }}} */
2556
2545
0 commit comments