Skip to content

Add stub for FormBuilderInterface::getForm() variadic params#957

Closed
marklabrecque-ab wants to merge 2 commits intomglaman:mainfrom
marklabrecque-ab:fix/892-form-builder-getform-variadic
Closed

Add stub for FormBuilderInterface::getForm() variadic params#957
marklabrecque-ab wants to merge 2 commits intomglaman:mainfrom
marklabrecque-ab:fix/892-form-builder-getform-variadic

Conversation

@marklabrecque-ab
Copy link
Copy Markdown
Contributor

Fixes #892.

Problem

In Drupal 10.x, FormBuilderInterface::getForm() uses a comment-style variadic parameter (/* , mixed ...$args */) rather than real PHP variadic syntax. PHPStan does not see the extra arguments and reports an error when calling getForm() with more than one parameter.

This has already been fixed in Drupal 11.x where the method signature uses proper mixed ...$args syntax.

Solution

Add a stub at stubs/Drupal/Core/Form/FormBuilderInterface.stub that declares the real variadic signature. The project's DrupalStubFilesExtension auto-discovers .stub files under stubs/, so no additional configuration is needed.

@mglaman
Copy link
Copy Markdown
Owner

mglaman commented Apr 7, 2026

I don't think stubs work this way, it only allows enhancing phpdoc and not the actual signatures

@mglaman
Copy link
Copy Markdown
Owner

mglaman commented Apr 8, 2026

Thanks for the contribution! Unfortunately this approach won't work — PHPStan stub files only override PHPDoc annotations, not native method signatures. The mixed ...$args variadic parameter added in the stub won't be recognized by PHPStan, so it won't resolve the false positive.

The root cause is Drupal 10's use of a comment-style variadic (/* , mixed ...$args */) instead of real PHP syntax. This was properly fixed in Drupal 11.x with a real variadic signature, so the issue doesn't exist there.

Given that Drupal 10 reaches end of life on December 9, 2026, we're going to close this without a fix. In the meantime, you can suppress the error with // @phpstan-ignore argument.count at the call site.

@mglaman mglaman closed this Apr 8, 2026
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.

Method Drupal\Core\Form\FormBuilderInterface::getForm() invoked with 2 parameters, 1 required.

2 participants