HH\inst_meth

Like fun, but with the purpose of calling an instance method on a specific object

namespace HH;

function inst_meth(
  $instance,
  string $meth_name,
);

This function can only be used on public methods; for private or protected methods, use a lambda instead.

Example:

<?hh
 class C {
  public function isOdd(int $i): bool { return $i % 2 == 1; }
  private function filter(Vector<int> $data): Vector<int> {
    $callback = inst_meth($this, 'isOdd');
    return $data->filter($callback);
  }
}

See also:

Parameters

  • $instance Any class object.
  • string $meth_name

Return Values

  • A - callback which will call $method when invoked.