Currently, when you typehint against “callable” in your method signatures, you can never be certain whether it accepts the parameters you are giving it or if the return type is what you'd expect. You can of course validate the return type, and catch exceptions about the invalid parameters and such when calling the callable, but that is not ideal.

This RFC proposes the definition of user-defined callables. Since “callable” is already a reserved keyword, this should not be a BC break. User-defined callables should be be both allowed to be namespaced like functions and classes, but also invoke the autoloader if they are not found in the current scope. A simple callable definition could look like this:

callable FilterCallable ( string $input ) : string ;

With such a callable in place, the user can now typehint against it, like they would against any other property, and be certain that it will accept the parameters they pass in, as well as guarantee the return type they expect:

function foo ( FilterCallable $filter ) : string { return $filter ( 'bar' ) ; } foo ( function ( string $foo ) : string { return trim ( $foo ) ; } ) ;

Of course, this works with any other kind of callable as well, be it a string, an array or an object.