Repository navigation
fix(hook): count the parameters of invokable objects and Class::method strings - #53
Merged
ogorzalka merged 1 commit intoNov 25, 2026
Conversation
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.
Branch:
fix/argument-detection-invokable-and-static-string(basemainat 22bc9be, after the 2.0.2 release). Found while typingcountParameters()for PHPStan level 7.Bug
When no argument count is given,
AbstractHook::countParameters()usedReflectionFunctionfor every callable that is not an array. It reads only closures and function names:Action::add('init', new Handler)(invokable object) threw aTypeError(ReflectionFunction::__construct(): Argument #1 must be of type Closure|string, Handler given), not aReflectionException, so it escaped theCallbackAnalysisFailedExceptionwrapper.Action::add('init', 'Handler::run')(static method as a string, callable in PHP and in WordPress) threwCallbackAnalysisFailedException: Function Handler::run() does not exist.Both are valid WordPress callbacks. Reproduced on
main.Fix
The count is read from
__invoke()for an invokable object and from the named static method for aClass::methodstring (ReflectionMethod; the single-argument form is deprecated in PHP 8.4, so the string is split). The reflection cache key of an object callback isClass::__invoke@idinstead ofserialize($object)(which could throw or be expensive).Proof
Two new tests (
AbstractHookTest, "Argument detection"): without the fix, 2 failed (TypeError,CallbackAnalysisFailedException); with it, they pass. Full suite 554 pass + 1 incomplete (onmaintoo). CHANGELOG[Unreleased]/ Fixed added (nothing else in the changelog touched; the release PR for 2.0.2 is merged).Not verified
Semgrep not run locally. Not run in a real WordPress (the WordPress suite needs a database).