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
24
24
. Fixed bug GH-17802 (\Dom\HTMLDocument querySelector attribute name is case
25
25
sensitive in HTML). (nielsdos)
26
26
. Fixed bug GH-17847 (xinclude destroys live node). (nielsdos)
27
+ . Fix using Dom\Node with Dom\XPath callbacks. (nielsdos)
27
28
28
29
- GD:
29
30
. 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
+ $ dom = Dom \XMLDocument::createFromString ('<root/> ' );
9
+ $ xpath = new Dom \XPath ($ dom );
10
+ $ xpath ->registerPhpFunctionNs ('urn:x ' , 'test ' , fn () => $ dom ->createElement ('foo ' ));
11
+ $ xpath ->registerNamespace ('x ' , 'urn:x ' );
12
+ $ test = $ xpath ->query ('x:test() ' );
13
+ var_dump ($ test [0 ]->nodeName );
14
+
15
+ ?>
16
+ --EXPECT--
17
+ string(3) "foo"
Original file line number Diff line number Diff line change 24
24
#if defined(HAVE_LIBXML ) && defined(HAVE_DOM )
25
25
26
26
#include "php_dom.h"
27
+ #include "internal_helpers.h"
27
28
#include <libxml/parserInternals.h>
28
29
29
30
static void xpath_callbacks_entry_dtor (zval * zv )
@@ -425,7 +426,8 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
425
426
}
426
427
427
428
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 ))))) {
429
431
xmlNode * nodep ;
430
432
dom_object * obj ;
431
433
if (xpath_callbacks -> node_list == NULL ) {
@@ -439,7 +441,7 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
439
441
} else if (Z_TYPE (callback_retval ) == IS_FALSE || Z_TYPE (callback_retval ) == IS_TRUE ) {
440
442
valuePush (ctxt , xmlXPathNewBoolean (Z_TYPE (callback_retval ) == IS_TRUE ));
441
443
} 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" );
443
445
zval_ptr_dtor (& callback_retval );
444
446
return FAILURE ;
445
447
} else {
Original file line number Diff line number Diff line change 28
28
}
29
29
?>
30
30
--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