@@ -45,6 +45,7 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry(void) /* {{{ */
45
45
46
46
static php_sxe_object * php_sxe_object_new (zend_class_entry * ce , zend_function * fptr_count );
47
47
static xmlNodePtr php_sxe_reset_iterator (php_sxe_object * sxe , int use_data );
48
+ static xmlNodePtr php_sxe_reset_iterator_no_clear_iter_data (php_sxe_object * sxe , int use_data );
48
49
static xmlNodePtr php_sxe_iterator_fetch (php_sxe_object * sxe , xmlNodePtr node , int use_data );
49
50
static void php_sxe_iterator_dtor (zend_object_iterator * iter );
50
51
static int php_sxe_iterator_valid (zend_object_iterator * iter );
@@ -77,6 +78,7 @@ static void _node_as_zval(php_sxe_object *sxe, xmlNodePtr node, zval *value, SXE
77
78
}
78
79
/* }}} */
79
80
81
+ /* Important: this overwrites the iterator data, if you wish to keep it use php_sxe_get_first_node_non_destructive() instead! */
80
82
static xmlNodePtr php_sxe_get_first_node (php_sxe_object * sxe , xmlNodePtr node ) /* {{{ */
81
83
{
82
84
php_sxe_object * intern ;
@@ -95,6 +97,15 @@ static xmlNodePtr php_sxe_get_first_node(php_sxe_object *sxe, xmlNodePtr node) /
95
97
}
96
98
/* }}} */
97
99
100
+ static xmlNodePtr php_sxe_get_first_node_non_destructive (php_sxe_object * sxe , xmlNodePtr node )
101
+ {
102
+ if (sxe && sxe -> iter .type != SXE_ITER_NONE ) {
103
+ return php_sxe_reset_iterator_no_clear_iter_data (sxe , false);
104
+ } else {
105
+ return node ;
106
+ }
107
+ }
108
+
98
109
static inline int match_ns (php_sxe_object * sxe , xmlNodePtr node , xmlChar * name , int prefix ) /* {{{ */
99
110
{
100
111
if (name == NULL && (node -> ns == NULL || node -> ns -> prefix == NULL )) {
@@ -1625,7 +1636,7 @@ PHP_METHOD(SimpleXMLElement, getName)
1625
1636
sxe = Z_SXEOBJ_P (ZEND_THIS );
1626
1637
1627
1638
GET_NODE (sxe , node );
1628
- node = php_sxe_get_first_node (sxe , node );
1639
+ node = php_sxe_get_first_node_non_destructive (sxe , node );
1629
1640
if (node ) {
1630
1641
namelen = xmlStrlen (node -> name );
1631
1642
RETURN_STRINGL ((char * )node -> name , namelen );
@@ -2450,15 +2461,9 @@ static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, i
2450
2461
}
2451
2462
/* }}} */
2452
2463
2453
- static xmlNodePtr php_sxe_reset_iterator (php_sxe_object * sxe , int use_data ) /* {{{ */
2464
+ static xmlNodePtr php_sxe_reset_iterator_no_clear_iter_data (php_sxe_object * sxe , int use_data )
2454
2465
{
2455
2466
xmlNodePtr node ;
2456
-
2457
- if (!Z_ISUNDEF (sxe -> iter .data )) {
2458
- zval_ptr_dtor (& sxe -> iter .data );
2459
- ZVAL_UNDEF (& sxe -> iter .data );
2460
- }
2461
-
2462
2467
GET_NODE (sxe , node )
2463
2468
2464
2469
if (node ) {
@@ -2471,10 +2476,23 @@ static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data) /* {
2471
2476
case SXE_ITER_ATTRLIST :
2472
2477
node = (xmlNodePtr ) node -> properties ;
2473
2478
}
2479
+ if (use_data ) {
2480
+ ZEND_ASSERT (Z_ISUNDEF (sxe -> iter .data ));
2481
+ }
2474
2482
return php_sxe_iterator_fetch (sxe , node , use_data );
2475
2483
}
2476
2484
return NULL ;
2477
2485
}
2486
+
2487
+ static xmlNodePtr php_sxe_reset_iterator (php_sxe_object * sxe , int use_data ) /* {{{ */
2488
+ {
2489
+ if (!Z_ISUNDEF (sxe -> iter .data )) {
2490
+ zval_ptr_dtor (& sxe -> iter .data );
2491
+ ZVAL_UNDEF (& sxe -> iter .data );
2492
+ }
2493
+
2494
+ return php_sxe_reset_iterator_no_clear_iter_data (sxe , use_data );
2495
+ }
2478
2496
/* }}} */
2479
2497
2480
2498
zend_object_iterator * php_sxe_get_iterator (zend_class_entry * ce , zval * object , int by_ref ) /* {{{ */
0 commit comments