You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
False positive Dynamic call to static method when mixing in another class and implementing __call and __callStatic #298
It's not clear to me whether DynamicCallOnStaticMethodsRule::processNode has enough information to operate properly at this point; nor even whether MixinMethodsClassReflectionExtension::findMethod does. It feels like somewhere along the line, either:
asking for a method called Mixer::method could return two versions, one static and one dynamic, or
the calling context (static/dynamic) could be passed to the method finding logic, so it can return the appropriate one
I'm actually wondering if the current behavior for mixins is entirely logical, given from what it looks like it currently simply does: __callStatic is defined implies all mixin calls are static. However, if __call is also present, I think this is simply not correct.
As I think it's generally very hard if not impossible to deduce which syntax is correct for mixin calls, as it heavily relies on the actual implementation of both __call and __callStatic. So maybe there should be some 'ambiguity' allowed, i.e. consider the method as neither static nor dynamic and never report issues, as I'd say false positives breaking code outweigh the potential benefits of spotting incorrect semantics.
(If interested in more concrete examples of errors reported on Laravel setups with this, LMK!)
Activity
msbit commentedon Feb 20, 2026
Looking over the main repo, I see the following issues that were resolved around this space:
phpstan/phpstan#3641
phpstan/phpstan#5536
With a common mixed in class defined as follows:
The first reported false positives with the following:
the second false positives with this modified version:
and what I'm reporting false positives with is a further modified version:
It's not clear to me whether
DynamicCallOnStaticMethodsRule::processNodehas enough information to operate properly at this point; nor even whetherMixinMethodsClassReflectionExtension::findMethoddoes. It feels like somewhere along the line, either:Mixer::methodcould return two versions, one static and one dynamic, orjnoordsij commentedon Apr 17, 2026
+1 here
I'm actually wondering if the current behavior for mixins is entirely logical, given from what it looks like it currently simply does:
__callStaticis defined implies all mixin calls are static. However, if__callis also present, I think this is simply not correct.For example, Laravel comes with a
Macroabletrait, whose implementation effectively allows calling any user-defined macro both dynamically and statically; see https://github.com/laravel/framework/blob/b6ee18a4e2feb3c80790de46d0fd78421afe65ea/src/Illuminate/Macroable/Traits/Macroable.php#L12. For any such class, probably both calls should be fine, so this should not be an immediate issue. However I think it is still somewhat deceptive coding that a static call is required where actually the result is a dynamic call.Then within some classes, there's further overriding of this behavior, which may introduce dynamic calls, see e.g.
https://github.com/laravel/framework/blob/b6ee18a4e2feb3c80790de46d0fd78421afe65ea/src/Illuminate/Routing/RouteRegistrar.php#L278-L312. For such cases, refactoring to a static call will actually break your code rather than improve it.
As I think it's generally very hard if not impossible to deduce which syntax is correct for mixin calls, as it heavily relies on the actual implementation of both
__calland__callStatic. So maybe there should be some 'ambiguity' allowed, i.e. consider the method as neither static nor dynamic and never report issues, as I'd say false positives breaking code outweigh the potential benefits of spotting incorrect semantics.(If interested in more concrete examples of errors reported on Laravel setups with this, LMK!)