diff --git a/reference/dom/domxpath/registerphpfunctions.xml b/reference/dom/domxpath/registerphpfunctions.xml index f2694f06cad2..997e954a98f1 100644 --- a/reference/dom/domxpath/registerphpfunctions.xml +++ b/reference/dom/domxpath/registerphpfunctions.xml @@ -29,8 +29,11 @@ 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 one of the following: + a string (a function name), + an indexed array of function names, + or an associative array with keys being the function name + and the associated value being the callable. @@ -45,6 +48,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 +171,43 @@ foreach ($books as $book) { echo $book->getElementsByTagName("title")->item(0)->nodeValue . "\n"; } +?> +]]> + + &example.outputs.similar; + + + + + + + + <methodname>DOMXPath::registerPHPFunctions</methodname> with a <type>callable</type> + +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 +221,7 @@ PHP Basics - + &reftitle.seealso; @@ -165,6 +229,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..197d17bdc867 100644 --- a/reference/xsl/xsltprocessor/registerphpfunctions.xml +++ b/reference/xsl/xsltprocessor/registerphpfunctions.xml @@ -28,20 +28,49 @@ XSLT. - This parameter can be either a string (a function name) or an array of - functions. + This parameter can be one of the following: + a string (a function name), + an indexed array of function names, + or an associative array with keys being the function name + and the associated value being the callable. + &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 +121,14 @@ echo $proc->transformToXML($xmldoc); + + + &reftitle.seealso; + + DOMXPath::registerPhpFunctions + + +