@@ -45,6 +45,7 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry(void) /* {{{ */
4545
4646static php_sxe_object * php_sxe_object_new (zend_class_entry * ce , zend_function * fptr_count );
4747static 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 );
4849static xmlNodePtr php_sxe_iterator_fetch (php_sxe_object * sxe , xmlNodePtr node , int use_data );
4950static void php_sxe_iterator_dtor (zend_object_iterator * iter );
5051static 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
7778}
7879/* }}} */
7980
81+ /* Important: this overwrites the iterator data, if you wish to keep it use php_sxe_get_first_node_non_destructive() instead! */
8082static xmlNodePtr php_sxe_get_first_node (php_sxe_object * sxe , xmlNodePtr node ) /* {{{ */
8183{
8284 php_sxe_object * intern ;
@@ -95,6 +97,15 @@ static xmlNodePtr php_sxe_get_first_node(php_sxe_object *sxe, xmlNodePtr node) /
9597}
9698/* }}} */
9799
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+
98109static inline int match_ns (php_sxe_object * sxe , xmlNodePtr node , xmlChar * name , int prefix ) /* {{{ */
99110{
100111 if (name == NULL && (node -> ns == NULL || node -> ns -> prefix == NULL )) {
@@ -1625,7 +1636,7 @@ PHP_METHOD(SimpleXMLElement, getName)
16251636 sxe = Z_SXEOBJ_P (ZEND_THIS );
16261637
16271638 GET_NODE (sxe , node );
1628- node = php_sxe_get_first_node (sxe , node );
1639+ node = php_sxe_get_first_node_non_destructive (sxe , node );
16291640 if (node ) {
16301641 namelen = xmlStrlen (node -> name );
16311642 RETURN_STRINGL ((char * )node -> name , namelen );
@@ -2450,15 +2461,9 @@ static xmlNodePtr php_sxe_iterator_fetch(php_sxe_object *sxe, xmlNodePtr node, i
24502461}
24512462/* }}} */
24522463
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 )
24542465{
24552466 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-
24622467 GET_NODE (sxe , node )
24632468
24642469 if (node ) {
@@ -2471,10 +2476,23 @@ static xmlNodePtr php_sxe_reset_iterator(php_sxe_object *sxe, int use_data) /* {
24712476 case SXE_ITER_ATTRLIST :
24722477 node = (xmlNodePtr ) node -> properties ;
24732478 }
2479+ if (use_data ) {
2480+ ZEND_ASSERT (Z_ISUNDEF (sxe -> iter .data ));
2481+ }
24742482 return php_sxe_iterator_fetch (sxe , node , use_data );
24752483 }
24762484 return NULL ;
24772485}
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+ }
24782496/* }}} */
24792497
24802498zend_object_iterator * php_sxe_get_iterator (zend_class_entry * ce , zval * object , int by_ref ) /* {{{ */
0 commit comments