Skip to content

Syntax for callable param/return types #580

@muglug

Description

@muglug

Edit: consensus has coalesced around the callable(type1, type2): returntype syntax

If we want to specify that a function receives a certain sort of closure, we should be able to use a type.

e.g.

/**
 * @param Closure<string, int, int> $foo
 */
function takeClosure(Closure $foo) {
  $a = $foo(3, 5);
}

// this is good
takeClosure(function(int $a, int $b) { return (string) ($a + $b); });
// this fails
takeClosure(function(int $a, string $b) { return (string) ($a + $b); });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions