-
-
Notifications
You must be signed in to change notification settings - Fork 6
[Bug] __invoke and __call magic methods are not supported #182
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingmagic-methodsMagic methods (__get, __call, __invoke...)Magic methods (__get, __call, __invoke...)php-compatibilityPHP compatibility / deviation from PHP behaviorPHP compatibility / deviation from PHP behaviortype-checkerStatic type checker / inference issuesStatic type checker / inference issues
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmagic-methodsMagic methods (__get, __call, __invoke...)Magic methods (__get, __call, __invoke...)php-compatibilityPHP compatibility / deviation from PHP behaviorPHP compatibility / deviation from PHP behaviortype-checkerStatic type checker / inference issuesStatic type checker / inference issues
Type
Fields
Give feedbackNo fields configured for issues without a type.
Description
Two important magic methods are not properly supported:
__invoke— Objects implementing__invokecannot be called using direct call syntax ($obj(42)).__call— Calls to undefined methods on an object that defines__callare not intercepted and instead produce "Undefined method" errors.Reproduction
__invoke
__call
Expected behavior
$obj(21)should invoke__invokeand return42$p->doSomething(1,2,3)should return"called:doSomething:1,2,3"Actual behavior
__invoke:Cannot call $obj — not a callable (got Object("CallableObj"))__call:Undefined method: CallableObj::fooEnvironment
elephc 0.21.8 vs PHP 8.4
Possible root cause
The type checker and call resolution logic do not consider
__invokewhen determining whether an expression is callable. Similarly, the method resolution for unknown methods does not fall back to__callon the receiver's class.Relevant areas:
src/types/checker/(callable detection and first-class callable logic)src/types/checker/functions/call_validation.rssrc/codegen/expr/calls/Additional context
Discovered while stress-testing magic methods in Round 2.
These are fundamental PHP object model features used in many libraries and DSLs.
Suggested labels:
bug,php-compatibility,type-checker,magic-methods