ReflectionDocBlock icon indicating copy to clipboard operation
ReflectionDocBlock copied to clipboard

Support for callable definitions

Open kelunik opened this issue 9 years ago • 4 comments

There should be support for callable definitions as types.

/**
 * Summary.
 *
 * @param callable(Throwable|Exception $error) $callback
 *         Callback executed upon uncaught errors.
 */

Currently this just makes the block fail to parse entirely.

kelunik avatar Sep 05 '16 06:09 kelunik

the signature should also support return types, e.g.

/**
 * Summary.
 *
 * @param callable(Throwable|Exception $error):MyReturnType $callback
 *         Callback executed upon uncaught errors.
 */

staabm avatar Sep 05 '16 07:09 staabm

This will complicate the parser, as spaces can't be used to separate the arguments anymore.

callable(Throwable|Exception $error, string $foo): MyReturnType
                            ^       ^      ^      ^

kelunik avatar Sep 05 '16 07:09 kelunik

@mvriel I think we should add this in the future. It makes a lot of sense to have a description for the exprected callable.

jaapio avatar Jul 14 '17 17:07 jaapio

When looking at this feature request it seemed very plausible to have this. On the other hand It would be strange to add arguments to the callable type of our type resolver. Since the php type doesn't have any arguments.

I don't know yet if and how we can implement this. Typically the arguments should be part of a some how complex description. Since we cannot modify the callable type for this. It looks like our current architecture is not able to support this use case.

I will leave this open for further discussion. Maybe we will find a solution when PRS-5 is continued

jaapio avatar Aug 04 '17 20:08 jaapio

Update on this one, we added support for callables in the type resolver. This will be part of our next release.

jaapio avatar Nov 19 '22 20:11 jaapio