@@ -78,25 +78,6 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
78
78
}
79
79
/* }}} */
80
80
81
- /* Important: this overwrites the iterator data, if you wish to keep it use php_sxe_get_first_node_non_destructive() instead! */
82
- static xmlNodePtr php_sxe_get_first_node (php_sxe_object * sxe , xmlNodePtr node ) /* {{{ */
83
- {
84
- php_sxe_object * intern ;
85
- xmlNodePtr retnode = NULL ;
86
-
87
- if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
88
- php_sxe_reset_iterator (sxe , 1 );
89
- if (!Z_ISUNDEF (sxe -> iter .data )) {
90
- intern = Z_SXEOBJ_P (& sxe -> iter .data );
91
- GET_NODE (intern , retnode )
92
- }
93
- return retnode ;
94
- } else {
95
- return node ;
96
- }
97
- }
98
- /* }}} */
99
-
100
81
static xmlNodePtr php_sxe_get_first_node_non_destructive (php_sxe_object * sxe , xmlNodePtr node )
101
82
{
102
83
if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
@@ -184,7 +165,7 @@ static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node,
184
165
if (sxe -> iter .type == SXE_ITER_NONE ) {
185
166
sxe -> iter .type = SXE_ITER_CHILD ;
186
167
}
187
- node = php_sxe_get_first_node (sxe , node );
168
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
188
169
sxe -> iter .type = orgtype ;
189
170
}
190
171
@@ -270,11 +251,11 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
270
251
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
271
252
attribs = 1 ;
272
253
elements = 0 ;
273
- node = php_sxe_get_first_node (sxe , node );
254
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
274
255
attr = (xmlAttrPtr )node ;
275
256
test = sxe -> iter .name != NULL ;
276
257
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
277
- node = php_sxe_get_first_node (sxe , node );
258
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
278
259
attr = node ? node -> properties : NULL ;
279
260
test = 0 ;
280
261
if (!member && node && node -> parent &&
@@ -322,7 +303,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
322
303
xmlNodePtr mynode = node ;
323
304
324
305
if (sxe -> iter .type == SXE_ITER_CHILD ) {
325
- node = php_sxe_get_first_node (sxe , node );
306
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
326
307
}
327
308
if (sxe -> iter .type == SXE_ITER_NONE ) {
328
309
if (member && Z_LVAL_P (member ) > 0 ) {
@@ -456,12 +437,12 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
456
437
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
457
438
attribs = 1 ;
458
439
elements = 0 ;
459
- node = php_sxe_get_first_node (sxe , node );
440
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
460
441
attr = (xmlAttrPtr )node ;
461
442
test = sxe -> iter .name != NULL ;
462
443
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
463
444
mynode = node ;
464
- node = php_sxe_get_first_node (sxe , node );
445
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
465
446
attr = node ? node -> properties : NULL ;
466
447
test = 0 ;
467
448
if (!member && node && node -> parent &&
@@ -707,19 +688,19 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
707
688
attribs = 0 ;
708
689
elements = 1 ;
709
690
if (sxe -> iter .type == SXE_ITER_CHILD ) {
710
- node = php_sxe_get_first_node (sxe , node );
691
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
711
692
}
712
693
}
713
694
}
714
695
715
696
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
716
697
attribs = 1 ;
717
698
elements = 0 ;
718
- node = php_sxe_get_first_node (sxe , node );
699
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
719
700
attr = (xmlAttrPtr )node ;
720
701
test = sxe -> iter .name != NULL ;
721
702
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
722
- node = php_sxe_get_first_node (sxe , node );
703
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
723
704
attr = node ? node -> properties : NULL ;
724
705
test = 0 ;
725
706
}
@@ -759,7 +740,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
759
740
if (elements ) {
760
741
if (Z_TYPE_P (member ) == IS_LONG ) {
761
742
if (sxe -> iter .type == SXE_ITER_CHILD ) {
762
- node = php_sxe_get_first_node (sxe , node );
743
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
763
744
}
764
745
node = sxe_get_element_by_offset (sxe , Z_LVAL_P (member ), node , NULL );
765
746
} else {
@@ -829,19 +810,19 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
829
810
attribs = 0 ;
830
811
elements = 1 ;
831
812
if (sxe -> iter .type == SXE_ITER_CHILD ) {
832
- node = php_sxe_get_first_node (sxe , node );
813
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
833
814
}
834
815
}
835
816
}
836
817
837
818
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
838
819
attribs = 1 ;
839
820
elements = 0 ;
840
- node = php_sxe_get_first_node (sxe , node );
821
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
841
822
attr = (xmlAttrPtr )node ;
842
823
test = sxe -> iter .name != NULL ;
843
824
} else if (sxe -> iter .type != SXE_ITER_CHILD ) {
844
- node = php_sxe_get_first_node (sxe , node );
825
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
845
826
attr = node ? node -> properties : NULL ;
846
827
test = 0 ;
847
828
}
@@ -878,7 +859,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
878
859
if (elements ) {
879
860
if (Z_TYPE_P (member ) == IS_LONG ) {
880
861
if (sxe -> iter .type == SXE_ITER_CHILD ) {
881
- node = php_sxe_get_first_node (sxe , node );
862
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
882
863
}
883
864
node = sxe_get_element_by_offset (sxe , Z_LVAL_P (member ), node , NULL );
884
865
if (node ) {
@@ -1011,7 +992,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
1011
992
}
1012
993
1013
994
if (sxe -> iter .type == SXE_ITER_ELEMENT ) {
1014
- node = php_sxe_get_first_node (sxe , node );
995
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1015
996
}
1016
997
if (!node || node -> type != XML_ENTITY_DECL ) {
1017
998
attr = node ? (xmlAttrPtr )node -> properties : NULL ;
@@ -1025,7 +1006,7 @@ static int sxe_prop_is_empty(zend_object *object) /* {{{ */
1025
1006
}
1026
1007
1027
1008
GET_NODE (sxe , node );
1028
- node = php_sxe_get_first_node (sxe , node );
1009
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1029
1010
is_empty = 1 ;
1030
1011
ZVAL_UNDEF (& iter_data );
1031
1012
if (node && sxe -> iter .type != SXE_ITER_ATTRLIST ) {
@@ -1120,7 +1101,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
1120
1101
}
1121
1102
if (is_debug || sxe -> iter .type != SXE_ITER_CHILD ) {
1122
1103
if (sxe -> iter .type == SXE_ITER_ELEMENT ) {
1123
- node = php_sxe_get_first_node (sxe , node );
1104
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1124
1105
}
1125
1106
if (!node || node -> type != XML_ENTITY_DECL ) {
1126
1107
attr = node ? (xmlAttrPtr )node -> properties : NULL ;
@@ -1142,7 +1123,7 @@ static HashTable *sxe_get_prop_hash(zend_object *object, int is_debug) /* {{{ */
1142
1123
}
1143
1124
1144
1125
GET_NODE (sxe , node );
1145
- node = php_sxe_get_first_node (sxe , node );
1126
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1146
1127
1147
1128
if (node && sxe -> iter .type != SXE_ITER_ATTRLIST ) {
1148
1129
if (node -> type == XML_ATTRIBUTE_NODE ) {
@@ -1301,7 +1282,7 @@ PHP_METHOD(SimpleXMLElement, xpath)
1301
1282
}
1302
1283
1303
1284
GET_NODE (sxe , nodeptr );
1304
- nodeptr = php_sxe_get_first_node (sxe , nodeptr );
1285
+ nodeptr = php_sxe_get_first_node_non_destructive (sxe , nodeptr );
1305
1286
if (!nodeptr ) {
1306
1287
return ;
1307
1288
}
@@ -1410,7 +1391,7 @@ PHP_METHOD(SimpleXMLElement, asXML)
1410
1391
1411
1392
sxe = Z_SXEOBJ_P (ZEND_THIS );
1412
1393
GET_NODE (sxe , node );
1413
- node = php_sxe_get_first_node (sxe , node );
1394
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1414
1395
1415
1396
if (!node ) {
1416
1397
RETURN_FALSE ;
@@ -1533,7 +1514,7 @@ PHP_METHOD(SimpleXMLElement, getNamespaces)
1533
1514
1534
1515
sxe = Z_SXEOBJ_P (ZEND_THIS );
1535
1516
GET_NODE (sxe , node );
1536
- node = php_sxe_get_first_node (sxe , node );
1517
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1537
1518
1538
1519
if (node ) {
1539
1520
if (node -> type == XML_ELEMENT_NODE ) {
@@ -1618,7 +1599,7 @@ PHP_METHOD(SimpleXMLElement, children)
1618
1599
}
1619
1600
1620
1601
GET_NODE (sxe , node );
1621
- node = php_sxe_get_first_node (sxe , node );
1602
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1622
1603
if (!node ) {
1623
1604
return ;
1624
1605
}
@@ -1667,7 +1648,7 @@ PHP_METHOD(SimpleXMLElement, attributes)
1667
1648
1668
1649
sxe = Z_SXEOBJ_P (ZEND_THIS );
1669
1650
GET_NODE (sxe , node );
1670
- node = php_sxe_get_first_node (sxe , node );
1651
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1671
1652
if (!node ) {
1672
1653
return ;
1673
1654
}
@@ -1708,7 +1689,7 @@ PHP_METHOD(SimpleXMLElement, addChild)
1708
1689
return ;
1709
1690
}
1710
1691
1711
- node = php_sxe_get_first_node (sxe , node );
1692
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1712
1693
1713
1694
if (node == NULL ) {
1714
1695
php_error_docref (NULL , E_WARNING , "Cannot add child. Parent is not a permanent member of the XML tree" );
@@ -1768,7 +1749,7 @@ PHP_METHOD(SimpleXMLElement, addAttribute)
1768
1749
sxe = Z_SXEOBJ_P (ZEND_THIS );
1769
1750
GET_NODE (sxe , node );
1770
1751
1771
- node = php_sxe_get_first_node (sxe , node );
1752
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1772
1753
1773
1754
if (node && node -> type != XML_ELEMENT_NODE ) {
1774
1755
node = node -> parent ;
@@ -2615,7 +2596,7 @@ void *simplexml_export_node(zval *object) /* {{{ */
2615
2596
2616
2597
sxe = Z_SXEOBJ_P (object );
2617
2598
GET_NODE (sxe , node );
2618
- return php_sxe_get_first_node (sxe , node );
2599
+ return php_sxe_get_first_node_non_destructive (sxe , node );
2619
2600
}
2620
2601
/* }}} */
2621
2602
0 commit comments