1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix using Dom\Node with Dom\XPath callbacks
This commit is contained in:
Niels Dossche
2025-02-22 16:00:45 +01:00
3 changed files with 22 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
--TEST--
Returning a Dom\Node from Dom\XPath callback
--EXTENSIONS--
dom
--FILE--
<?php
$dom = Dom\XMLDocument::createFromString('<root/>');
$xpath = new Dom\XPath($dom);
$xpath->registerPhpFunctionNs('urn:x', 'test', fn() => $dom->createElement('foo'));
$xpath->registerNamespace('x', 'urn:x');
$test = $xpath->query('x:test()');
var_dump($test[0]->nodeName);
?>
--EXPECT--
string(3) "foo"

View File

@@ -24,6 +24,7 @@
#if defined(HAVE_LIBXML) && defined(HAVE_DOM)
#include "php_dom.h"
#include "internal_helpers.h"
#include <libxml/parserInternals.h>
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
}
if (Z_TYPE(callback_retval) != IS_UNDEF) {
if (Z_TYPE(callback_retval) == IS_OBJECT && instanceof_function(Z_OBJCE(callback_retval), dom_node_class_entry)) {
if (Z_TYPE(callback_retval) == IS_OBJECT
&& (instanceof_function(Z_OBJCE(callback_retval), dom_get_node_ce(php_dom_follow_spec_node((const xmlNode *) ctxt->context->doc))))) {
xmlNode *nodep;
dom_object *obj;
if (xpath_callbacks->node_list == NULL) {
@@ -439,7 +441,7 @@ static zend_result php_dom_xpath_callback_dispatch(php_dom_xpath_callbacks *xpat
} else if (Z_TYPE(callback_retval) == IS_FALSE || Z_TYPE(callback_retval) == IS_TRUE) {
valuePush(ctxt, xmlXPathNewBoolean(Z_TYPE(callback_retval) == IS_TRUE));
} else if (Z_TYPE(callback_retval) == IS_OBJECT) {
zend_type_error("Only objects that are instances of DOMNode can be converted to an XPath expression");
zend_type_error("Only objects that are instances of DOM nodes can be converted to an XPath expression");
zval_ptr_dtor(&callback_retval);
return FAILURE;
} else {

View File

@@ -28,4 +28,4 @@ try {
}
?>
--EXPECT--
Only objects that are instances of DOMNode can be converted to an XPath expression
Only objects that are instances of DOM nodes can be converted to an XPath expression