From 30b3211cf861905dc52ce19b4ec81f759a1b81e2 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Thu, 5 Feb 2026 10:14:56 +0100 Subject: [PATCH] Fix with not rendering correctly When contains , skip link/parentheses processing in format_function_text() and output plain text instead. Uses the role stack pattern already established by format_constant(). Fixes php/phd#171 --- phpdotnet/phd/Package/PHP/XHTML.php | 12 ++++++ phpdotnet/phd/Render.php | 2 +- .../data/function_replaceable_rendering.xml | 18 +++++++++ .../php/function_replaceable_rendering.phpt | 38 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/package/php/data/function_replaceable_rendering.xml create mode 100644 tests/package/php/function_replaceable_rendering.phpt diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index 6d8a4bec..878afb83 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -827,12 +827,24 @@ public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag public function format_function($open, $tag, $attrs, $props) { if ($open) { + if (str_contains($props["innerXml"], 'pushRole("function_replaceable"); + } return ''; } + + if ($this->getRole() === "function_replaceable") { + $this->popRole(); + } + return ""; } public function format_function_text($value, $tag, $display_value = null) { + if ($this->getRole() === "function_replaceable") { + return $this->TEXT($value); + } + static $non_functions = array( "echo" => true, "print" => true, "include" => true, "include_once" => true, diff --git a/phpdotnet/phd/Render.php b/phpdotnet/phd/Render.php index 5e4201cd..eeacc68e 100644 --- a/phpdotnet/phd/Render.php +++ b/phpdotnet/phd/Render.php @@ -77,7 +77,7 @@ public function execute(Reader $r) { /* {{{ */ $r->name === "type" || $r->name === "classsynopsis" || $r->name === "qandaset" || - in_array($r->name, ["methodsynopsis", "constructorsynopsis", "destructorsynopsis", "constant"], true) + in_array($r->name, ["methodsynopsis", "constructorsynopsis", "destructorsynopsis", "constant", "function"], true) ) ) { $innerXml = $r->readInnerXml(); diff --git a/tests/package/php/data/function_replaceable_rendering.xml b/tests/package/php/data/function_replaceable_rendering.xml new file mode 100644 index 00000000..75168e33 --- /dev/null +++ b/tests/package/php/data/function_replaceable_rendering.xml @@ -0,0 +1,18 @@ + + + +
+ 1. Function with replaceable + + xml_set_* + +
+ +
+ 2. Normal function (no replaceable) + + strlen + +
+ +
diff --git a/tests/package/php/function_replaceable_rendering.phpt b/tests/package/php/function_replaceable_rendering.phpt new file mode 100644 index 00000000..bd2ae496 --- /dev/null +++ b/tests/package/php/function_replaceable_rendering.phpt @@ -0,0 +1,38 @@ +--TEST-- +Function with replaceable rendering +--FILE-- +xmlFile = $xmlFile; + +$format = new TestPHPChunkedXHTML($config, $outputHandler); + +$render = new TestRender(new Reader($outputHandler), $config, $format); + +$render->run(); +?> +--EXPECTF-- +Filename: function_replaceable_rendering.html +Content: +
+ +
+

1. Function with replaceable

+

+ xml_set_* +

+
+ +
+

2. Normal function (no replaceable)

+

+ strlen() +

+
+ +