File tree Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Expand file tree Collapse file tree 4 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ PHP                                                                        NEWS
2424  . Fixed bug GH-17802 (\Dom\HTMLDocument querySelector attribute name is case
2525    sensitive in HTML). (nielsdos)
2626  . Fixed bug GH-17847 (xinclude destroys live node). (nielsdos)
27+   . Fix using Dom\Node with Dom\XPath callbacks. (nielsdos)
2728
2829- GD:
2930  . Fixed bug GH-17703 (imagescale with both width and height negative values
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Returning a Dom\Node from Dom\XPath callback
3+ --EXTENSIONS--
4+ dom
5+ --FILE--
6+ <?php 
7+ 
8+ $ domDom \XMLDocument::createFromString ('<root/> ' );
9+ $ xpathnew  Dom \XPath ($ dom
10+ $ xpathregisterPhpFunctionNs ('urn:x ' , 'test ' , fn () => $ domcreateElement ('foo ' ));
11+ $ xpathregisterNamespace ('x ' , 'urn:x ' );
12+ $ test$ xpathquery ('x:test() ' );
13+ var_dump ($ test0 ]->nodeName );
14+ 
15+ ?> 
16+ --EXPECT--
17+ string(3) "foo"
Original file line number Diff line number Diff line change 2424#if  defined(HAVE_LIBXML ) &&  defined(HAVE_DOM )
2525
2626#include  "php_dom.h" 
27+ #include  "internal_helpers.h" 
2728#include  <libxml/parserInternals.h> 
2829
2930static  void  xpath_callbacks_entry_dtor (zval  * zv )
@@ -425,7 +426,8 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
425426	}
426427
427428	if  (Z_TYPE (callback_retval ) !=  IS_UNDEF ) {
428- 		if  (Z_TYPE (callback_retval ) ==  IS_OBJECT  &&  instanceof_function (Z_OBJCE (callback_retval ), dom_node_class_entry )) {
429+ 		if  (Z_TYPE (callback_retval ) ==  IS_OBJECT 
430+ 		 &&  (instanceof_function (Z_OBJCE (callback_retval ), dom_get_node_ce (php_dom_follow_spec_node ((const  xmlNode  * ) ctxt -> context -> doc ))))) {
429431			xmlNode  * nodep ;
430432			dom_object  * obj ;
431433			if  (xpath_callbacks -> node_list  ==  NULL ) {
@@ -439,7 +441,7 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
439441		} else  if  (Z_TYPE (callback_retval ) ==  IS_FALSE  ||  Z_TYPE (callback_retval ) ==  IS_TRUE ) {
440442			valuePush (ctxt , xmlXPathNewBoolean (Z_TYPE (callback_retval ) ==  IS_TRUE ));
441443		} else  if  (Z_TYPE (callback_retval ) ==  IS_OBJECT ) {
442- 			zend_type_error ("Only objects that are instances of DOMNode  can be converted to an XPath expression" );
444+ 			zend_type_error ("Only objects that are instances of DOM nodes  can be converted to an XPath expression" );
443445			zval_ptr_dtor (& callback_retval );
444446			return  FAILURE ;
445447		} else  {
Original file line number Diff line number Diff line change 2828}
2929?> 
3030--EXPECT--
31- Only objects that are instances of DOMNode  can be converted to an XPath expression
31+ Only objects that are instances of DOM nodes  can be converted to an XPath expression
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments