Skip to content

Reject optional parameters in non-@api code - #6878

Open
ondrejmirtes wants to merge 2 commits into
2.3.xfrom
no-optional-parameters
Open

ondrejmirtes wants to merge 2 commits into
2.3.xfrom
no-optional-parameters

Conversation

@ondrejmirtes

@ondrejmirtes ondrejmirtes commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Adds a build rule (build/PHPStan/Build/NoOptionalParameterRule.php) that reports optional parameters in methods and functions that aren't @api. Constructors count as non-@api even in @api classes unless the constructor has its own @api tag. Closures and arrow functions aren't checked. Parameters that are optional in an ancestor are skipped. Existing violations are recorded in build/baseline-optional-parameters.neon.

The second commit makes the 272 optional parameters added in the last 135 days (since e300c7eae) required, and every caller now passes the former default explicitly. The turbo-ext native mirrors follow: regenerated arginfo, required ZPP arguments, and native calls into PHP that pass full argument lists. The baseline goes from 467 to 195 entries.

These stay optional on purpose:

  • 29 parameters that follow an older optional parameter
  • TemplateTypeTrait::isValidVariance() $strict, because the interface requires it
  • CachedParser::__construct() $cachedSourceBytesMax, because Larastan constructs the class
  • OpenSslCipherMethodsProvider::__construct() $supportedCipherMethods, because DI autowiring needs it
  • the last 10 ExpressionResult::__construct() parameters, which the generated ExpressionResultFactory doesn't pass

Verified locally:

  • make tests passes with and without the turbo extension.
  • In turbo-ext: smoke.php, the differential tests, walk-trace.php, signature-parity and side-by-side.php all pass.
  • bin/phpstan analyse -c build/phpstan.neon is clean, and its raw output is identical with and without turbo.

…functions

Existing violations are recorded in build/baseline-optional-parameters.neon.

Amp-Thread-ID: https://ampcode.com/threads/T-01a18404-a5f9-74cf-bb1b-815927dc7033
Parameters that became optional in the last 135 days are now required,
and every caller passes the former default explicitly. The native mirrors
in turbo-ext follow: regenerated arginfo, required ZPP arguments, and
native calls into PHP that pass the full argument lists.

Kept optional: parameters after an older optional parameter, the
TemplateTypeTrait::isValidVariance() $strict required by the interface,
CachedParser's $cachedSourceBytesMax (constructed by Larastan),
OpenSslCipherMethodsProvider's $supportedCipherMethods (DI autowiring),
and the trailing ExpressionResult constructor parameters that the
generated ExpressionResultFactory does not pass.

Amp-Thread-ID: https://ampcode.com/threads/T-01a18404-a5f9-74cf-bb1b-815927dc7033
@ondrejmirtes
ondrejmirtes force-pushed the no-optional-parameters branch from 6a188ee to 7e47baa Compare October 28, 2026 22:05
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.

1 participant