Re: [RFC] Callable Types
| From: | Nikita Nefedov | Date: | Sat, 23 Apr 2016 12:35:26 +0000 |
| Subject: | Re: [RFC] Callable Types | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92656@lists.php.net to get a copy of this message | ||
On Sat, 23 Apr 2016 14:18:56 +0300, Dan Ackroyd <danack@basereality.com> wrote:
On 22 April 2016 at 05:12, Marcio Almada <marcio.web2@gmail.com> wrote:Hey Dan, thanks for reviewing. I have just added a paragraph about nested callables, I'll copy paste it here: Nested callables can be used with no imposed limit on the nesting level.Hello everyone, We just completed the draft for the "Callable Types" RFC.There seems to be one thing missing from the RFC; please could you add an example where the parameter and return types are also 'typed' callables? Presumably it would look something like this? function reduce(int $a, int $b, callable(int, callable(int, int):int $math):int $reducer): callable(int, int):int { return $reducer($a, $b); } Are there any limits to how far down the callable type can be defined ? cheers Dan
function foo(callable(callable(int)) $cb) {
$cb(function (int $i) {
var_dump($i);
});
}
foo(function (callable(int) $intPrinter) {
$intPrinter(123);
});
There's currently no way to reference callable signature from within itself, meaning there's no way to make recursive signatures like below:
function bar(callable(int $number): callable(int $number): callable(int $number): parent_callable $recursiveCb) { // this wouldn't work currently
}
To add to that, nested callables can get pretty unreadable quickly, both of these problems would be best solved by a typedef feature of some kind, added to PHP later.