From 0102bebaeff074257187a29a78b4e0bef42b0c2b Mon Sep 17 00:00:00 2001
From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Date: Wed, 20 Nov 2024 22:08:23 +0100
Subject: [PATCH 1/4] PHP 8.4: Document registerPhpFunctions() changes
---
.../dom/domxpath/registerphpfunctions.xml | 69 ++++++++++++++++++-
.../xsltprocessor/registerphpfunctions.xml | 41 ++++++++++-
2 files changed, 105 insertions(+), 5 deletions(-)
diff --git a/reference/dom/domxpath/registerphpfunctions.xml b/reference/dom/domxpath/registerphpfunctions.xml
index f2694f06cad2..a8d9867c0845 100644
--- a/reference/dom/domxpath/registerphpfunctions.xml
+++ b/reference/dom/domxpath/registerphpfunctions.xml
@@ -29,8 +29,9 @@
Use this parameter to only allow certain functions to be called from XPath.
- This parameter can be either a string (a function name) or
- an array of function names.
+ This parameter can be either a string (a function name), or
+ an array of function names or
+ string => callable entries.
@@ -45,6 +46,30 @@
+
+ &reftitle.changelog;
+
+
+
+
+ &Version;
+ &Description;
+
+
+
+
+ 8.4.0
+
+ It is now possible to use callables for callbacks
+ when using restrict with array
+ entries.
+
+
+
+
+
+
+
&reftitle.examples;
@@ -144,6 +169,43 @@ foreach ($books as $book) {
echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
}
+?>
+]]>
+
+ &example.outputs.similar;
+
+
+
+
+
+
+
+ DOMXPath::registerPHPFunctions with a callable
+
+load('book.xml');
+
+$xpath = new DOMXPath($doc);
+
+// Register the php: namespace (required)
+$xpath->registerNamespace("php", "http://php.net/xpath");
+
+// Register PHP functions (has_multiple only)
+$xpath->registerPHPFunctions(["has_multiple" => fn ($nodes) => count($nodes) > 1]);
+
+// Filter books with multiple authors
+$books = $xpath->query('//book[php:function("has_multiple", author)]');
+
+echo "Books with multiple authors:\n";
+foreach ($books as $book) {
+ echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n";
+}
+
?>
]]>
@@ -157,7 +219,7 @@ PHP Basics
-
+
&reftitle.seealso;
@@ -165,6 +227,7 @@ PHP Basics
DOMXPath::registerNamespace
DOMXPath::query
DOMXPath::evaluate
+ XSLTProcessor::registerPHPFunctions
diff --git a/reference/xsl/xsltprocessor/registerphpfunctions.xml b/reference/xsl/xsltprocessor/registerphpfunctions.xml
index 579c5c129fb5..3f7107d0ac76 100644
--- a/reference/xsl/xsltprocessor/registerphpfunctions.xml
+++ b/reference/xsl/xsltprocessor/registerphpfunctions.xml
@@ -28,20 +28,47 @@
XSLT.
- This parameter can be either a string (a function name) or an array of
- functions.
+ This parameter can be either a string (a function name), or
+ an array of function names or
+ string => callable entries.
+
&reftitle.returnvalues;
&return.void;
+
+
+ &reftitle.changelog;
+
+
+
+
+ &Version;
+ &Description;
+
+
+
+
+ 8.4.0
+
+ It is now possible to use callables for callbacks
+ when using restrict with array
+ entries.
+
+
+
+
+
+
+
&reftitle.examples;
@@ -92,6 +119,16 @@ echo $proc->transformToXML($xmldoc);
+
+
+ &reftitle.seealso;
+
+
+ DOMXPath::registerPhpFunctions
+
+
+
+