rfc:invokable
Request for Comments: Invokable
- Version: 1.0
- Date: 2008-08-02
- Author: Etienne Kneuss colder@php.net
- Status: Under Discussion
Introduction
Closures were implemented in PHP_5_3. For them, an __invoke() magic method was implemented, but not only for closures, every classes can define their own __invoke() and then use $obj();
Proposal
Currently, there is no sane way to detect whether an object can be invoked or not. What this RFC proposes is an interface that covers __invoke():
interface Invokable { public function __invoke($args); } class Closure implements Invokable { /* ... */ } class MyClass implements Invokable { /* ... */ }
And make $obj(); possible only if the interface is implemented, and not only the method. We have other examples of magic features that are covered by interfaces, like ArrayAccess or Iterator/Traversable.
rfc/invokable.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1