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

namespace HH;

function fun(
  string $func_name,

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:

$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:


  • string $func_name

Return Values

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