Open
Description
Description
The following code:
<?php
interface I {
public function test(): callable;
}
class Invokable {
public function __invoke() {}
}
var_dump(is_callable(new Invokable()));
class C implements I {
public function test(): Invokable {}
}
Resulted in this output:
bool(true)
Fatal error: Declaration of C::test(): Invokable must be compatible with I::test(): callable in /in/PfBWX on line 10
Process exited with code 255.
Methods should be able to restrict callable return types from interfaces and parent classes to more specific types that unconditionally fall within the callable type. Any class or interface that contains an __invoke method should be considered a callable type an be allowed as a more specific subtype of callable in subclasses. Also \Closure should be allowed as well.
PHP Version
8.4.5
Operating System
No response