Skip to content

Join union types when rendering callable parameters and return - #4114

Open
lacatoire wants to merge 1 commit into
phpDocumentor:masterfrom
lacatoire:fix/issue-3995-callable-union-type
Open

Join union types when rendering callable parameters and return#4114
lacatoire wants to merge 1 commit into
phpDocumentor:masterfrom
lacatoire:fix/issue-3995-callable-union-type

Conversation

@lacatoire

Copy link
Copy Markdown
Contributor

LinkRenderer::render is typed string|list<string>, and the IterableAdapter matches any Compound type because Compound implements IteratorAggregate. CallableAdapter used to feed that result straight into sprintf("%s", $type), which triggered a PHP Array to string conversion warning for any callable that carried a union type in its signature (see #3995).

Route both parameter and return type rendering through a small renderType helper that joins list<string> results with a | separator, mirroring what AbstractListAdapter already does for array/iterable element types.

Covered by new parameterised unit tests for union parameters, union return type, named/variadic/mixed union parameters.

Fixes #3995

@lacatoire
lacatoire force-pushed the fix/issue-3995-callable-union-type branch from e635b5f to 7554951 Compare April 17, 2026 15:39
LinkRenderer::render returns string|list<string>, and the IterableAdapter
matches any Compound type because Compound implements IteratorAggregate.
CallableAdapter previously fed that result straight into sprintf, which
triggered a PHP "Array to string conversion" warning for any callable
that used a union type in its signature.

Route both parameter and return type rendering through a small
renderType helper that joins list<string> results with a | separator,
mirroring what AbstractListAdapter already does for array/iterable
element types.

Fixes phpDocumentor#3995
@lacatoire
lacatoire force-pushed the fix/issue-3995-callable-union-type branch from 7554951 to 3e517ae Compare April 17, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

phpdoc triggers array to string conversion warnings in the Twig Callable Renderer

1 participant