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
<?phpinterface I {
publicfunctiontest(): callable;
}
class Invokable {
publicfunction__invoke() {}
}
var_dump(is_callable(newInvokable()));
class C implements I {
publicfunctiontest(): 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
The text was updated successfully, but these errors were encountered:
I suppose we could do some duck typing here, and check for zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE)), or preferably store it in ce->__invoke like we do the other magic methods. But an interface analogous to Stringable would surely be cleaner.
Description
The following code:
Resulted in this output:
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
The text was updated successfully, but these errors were encountered: