Repository navigation
Conversation
…callbacks Reading options from a closure invoked after the lazy default or normalizer has returned bypasses the circular dependency detection of the OptionsResolver. The rule reports closures and arrow functions capturing a variable of type Symfony\Component\OptionsResolver\Options (but not OptionsResolver itself), unless the closure is invoked immediately. Closes phpstan#454 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@ondrejmirtes the lowest deps jobs are failing because they install |
Contributor
Author
|
it looks like |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #454
Lazy defaults and normalizers receive an
Optionsobject whoseArrayAccessreads detect circular dependencies between options. That detection only works while the callback runs. A closure that captures$optionsand reads it later bypasses it.This rule reports closures and arrow functions that capture a variable of type
Symfony\Component\OptionsResolver\Options. Variables of typeOptionsResolverare not reported, because nested options callbacks receive a real resolver.Identifier:
symfonyOptionsResolver.optionsCapturedWhat is reported
use ($options)oruse (&$options).Closures that run right away
These are allowed:
(function () use ($options) { ... })()and(fn () => ...)()NodeScopeResolver::callCallbackImmediately(): callable parameters of functions such asarray_map()count by default, and method parameters count only when annotated@param-immediately-invoked-callable.PHPStan provides the parameter receiving the closure through
Scope::getFunctionCallStackWithParameters(). The call stack is also set for closures nested deeper inside an argument, such asfoo([fn () => ...]). A small parser visitor registered inrules.neontherefore marks closures that are direct call arguments. The same visitor marks(fn)()calls, so the rule does not depend on PHPStan's internalImmediatelyInvokedClosureVisitor.Other changes
symfony/options-resolveradded to require-dev. It was previously installed only throughsymfony/form.🤖 Generated with Claude Code