HH\fun

fun is a special function used to create a "pointer" to a function in a typeable way

Description

function fun(
  string $s,
)

The typechecker disallows using strings as functions; you must instead use fun() to make sure the typechecker looks up the function signature and returns a proper function type.

For example:

<?hh
$a = [1, 2, 3];

$c = 'count';
$c($a); // Type error: cannot call a string.

$c = fun('count');
$c($a); // Legal: by using fun(), $c is now a callable with the right type.

See also:

Parameters

  • $s Function to look up. Must be a constant string.

Return Values

  • A - callback which will call $s when invoked, but has the proper Hack function signature.