Repository navigation
Fix: an intersection whose later member has __invoke isn't callable - #14610
Merged
alies-dev merged 10 commits intoNov 22, 2026
Merged
Conversation
… as callable vimeo#14588 The invokable branch of getCallableFromAtomic() looked up __invoke on the first member of an object type only, and only for classes. It now resolves the member that supplies __invoke (interfaces, enums and abstract classes of an invokable interface included), binds the receiver and method templates against it, and keeps the conditional return unresolved. Where several members have __invoke the callable is the first member's if that is a class, as before, and an intersection with none first is callable only if one of them has the signature expected. The callable param check and calls of $h(...) use the same supplier, so an interface or a later intersection member gives the signature of its __invoke.
…ions like a closure vimeo#14588 array_map() and the other array functions compared the element types with the parameters of a closure only, so an object whose __invoke takes another type was accepted silently once it counted as callable. They now resolve its __invoke callable, and take the implicit variadic flag of the method (func_get_args()) into account as they do for closures.
…rs takes the elements vimeo#14588 Where several members of an object have __invoke and the first has none, the array functions skipped the element check. They now report the callback unless one of the members takes the element types, with the comparison of the callable param check.
…ass that has __invoke vimeo#14588 Interfaces and enums are no longer taken for the supplier of __invoke, so they are handled as before, and neither is the choice between several members. The supplier is the first class of the type that has __invoke. is_callable() keeps the object type of such an intersection, as it does for a plain class.
…ot a Closure param's argument vimeo#14588 The argument of a callable param is replaced by its callable early, which made an invokable object a parent type of a Closure param and gave it ArgumentTypeCoercion only, where PHP throws a TypeError. The replacement is skipped for a Closure param unless the argument is a Closure.
…and keep marking Closure param callables used vimeo#14588 An interface as the first member of an intersection that has __invoke is handled as before, whatever the later members have. The method an array or a string callable names is still marked as used when it is given to a Closure param, and a string or an object is no longer swapped for its callable there by the higher-order argument handler.
…InvalidArgument A string is not a Closure, so it is rejected as such, not as a scalar of the wrong type.
alies-dev
marked this pull request as ready for review
November 22, 2026 02:03
Contributor
✅ Performance: unchanged · Types: unchanged
How to read this table
head 3b96031 · base d80ebf0 (merge-base) · workflow run |
__invoke isn't callable
…s __invoke, nothing more vimeo#14588 An intersection whose __invoke comes from a later class behaves as that class alone: one helper finds the member, and the Closure param strictness, the element checks of object callbacks and the method template binding of the invokable path are removed again.
… before vimeo#14588 getInvokeMember() accepted any first member with __invoke, so an enum passed the callable gate while the resolver, which takes classes only, gave no signature to compare: the enum was accepted as any callable. The first member must be a class or an interface again.
…ction-later-invoke # Conflicts: # tests/ArrayFunctionCallTest.php # tests/CallableTest.php
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.
Psalm doesn't treat an intersection as callable when
__invokecomes from a class that isn't its first member, in any form (acallableparameter,$h(...),$h($x),Closure::fromCallable(),array_map(),array_walk(),array_filter()). The intersection now behaves as that class alone.Before
After
Part of #14588