@@ -43,6 +43,16 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry(void) /* {{{ */
43
43
}
44
44
/* }}} */
45
45
46
+ /* Similar to php_dom_invalidate_node_list_cache(), but SimpleXML shouldn't depend on ext/dom. */
47
+ static zend_always_inline void php_sxe_invalidate_node_list_cache (xmlNodePtr node )
48
+ {
49
+ ZEND_ASSERT (node != NULL );
50
+ xmlDocPtr docp = node -> doc ;
51
+ if (docp && docp -> _private ) {
52
+ php_libxml_invalidate_node_list_cache (docp -> _private );
53
+ }
54
+ }
55
+
46
56
static php_sxe_object * php_sxe_object_new (zend_class_entry * ce , zend_function * fptr_count );
47
57
static xmlNodePtr php_sxe_reset_iterator (php_sxe_object * sxe , int use_data );
48
58
static xmlNodePtr php_sxe_iterator_fetch (php_sxe_object * sxe , xmlNodePtr node , int use_data );
@@ -442,6 +452,8 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
442
452
443
453
GET_NODE (sxe , node );
444
454
455
+ php_sxe_invalidate_node_list_cache (node );
456
+
445
457
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
446
458
attribs = 1 ;
447
459
elements = 0 ;
@@ -813,6 +825,8 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
813
825
814
826
GET_NODE (sxe , node );
815
827
828
+ php_sxe_invalidate_node_list_cache (node );
829
+
816
830
if (Z_TYPE_P (member ) == IS_LONG ) {
817
831
if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
818
832
attribs = 0 ;
@@ -1686,6 +1700,8 @@ PHP_METHOD(SimpleXMLElement, addChild)
1686
1700
sxe = Z_SXEOBJ_P (ZEND_THIS );
1687
1701
GET_NODE (sxe , node );
1688
1702
1703
+ php_sxe_invalidate_node_list_cache (node );
1704
+
1689
1705
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
1690
1706
php_error_docref (NULL , E_WARNING , "Cannot add element to attributes" );
1691
1707
return ;
0 commit comments