diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index 53a78c9c..80ea05d6 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -879,7 +879,19 @@ public function format_function_text($value, $tag, $display_value = null) { $filename = "function." . str_replace("_", "-", $value); } else { $ref = $this->normalizeFQN($value); - $filename = $this->getRefnameLink($ref); + $filename = null; + /* A bare methodname may collide with a global function + * (e.g. Serializable::serialize vs serialize), so prefer + * a method of the class currently being documented */ + if ($tag === "methodname" + && !str_contains($ref, "::") + && $this->cchunk["class_name_ref"] !== null + ) { + $filename = $this->getRefnameLink($this->cchunk["class_name_ref"] . "::" . $ref); + } + if ($filename === null) { + $filename = $this->getRefnameLink($ref); + } } if ($filename !== null) { if ($this->CURRENT_ID !== $filename) { diff --git a/tests/package/php/class_and_method_link_rendering_002.phpt b/tests/package/php/class_and_method_link_rendering_002.phpt new file mode 100644 index 00000000..b4d654a3 --- /dev/null +++ b/tests/package/php/class_and_method_link_rendering_002.phpt @@ -0,0 +1,79 @@ +--TEST-- +Class and method link rendering 002: bare methodname colliding with a global function +--FILE-- +xmlFile = __DIR__ . "/data/class_and_method_link_rendering_002.xml"; + +$indices = [ + [ + "docbook_id" => "function.conflictingname", + "filename" => "function.conflictingname", + ], + [ + "docbook_id" => "myclass.conflictingname", + "filename" => "myclass.conflictingname", + ], + [ + "docbook_id" => "function.onlyfunction", + "filename" => "function.onlyfunction", + ], +]; + +$format = new TestPHPChunkedXHTML($config, $outputHandler); + +foreach ($indices as $index) { + $format->SQLiteIndex( + null, // $context, + null, // $index, + $index["docbook_id"] ?? "", // $id, + $index["filename"] ?? "", // $filename, + $index["parent_id"] ?? "", // $parent, + $index["sdesc"] ?? "", // $sdesc, + $index["ldesc"] ?? "", // $ldesc, + $index["element"] ?? "", // $element, + $index["previous"] ?? "", // $previous, + $index["next"] ?? "", // $next, + $index["chunk"] ?? 0, // $chunk + ); +} + +$format->addRefname("function.conflictingname", "conflictingname"); +$format->addRefname("myclass.conflictingname", "myclass::conflictingname"); +$format->addRefname("function.onlyfunction", "onlyfunction"); + +$render = new TestRender(new Reader($outputHandler), $config, $format); + +$render->run(); +?> +--EXPECTF-- +Filename: class.myclass.html +Content: +
+ +

The MyClass class

+ + +

(No version information available, might only be in Git)

+ +
+

1. Bare methodname colliding with a global function links to the method of the current class

+ conflictingName() +
+ +
+

2. Function with the same name still links to the global function

+ conflictingName() +
+ +
+

3. Bare methodname without a matching method falls back to the global function

+ onlyFunction() +
+ +
+ +
diff --git a/tests/package/php/data/class_and_method_link_rendering_002.xml b/tests/package/php/data/class_and_method_link_rendering_002.xml new file mode 100644 index 00000000..186c7e18 --- /dev/null +++ b/tests/package/php/data/class_and_method_link_rendering_002.xml @@ -0,0 +1,26 @@ + + + + The MyClass class + MyClass + + + +
+ 1. Bare methodname colliding with a global function links to the method of the current class + conflictingName +
+ +
+ 2. Function with the same name still links to the global function + conflictingName +
+ +
+ 3. Bare methodname without a matching method falls back to the global function + onlyFunction +
+ +
+ +