Convert a PHP method to a closure

Since PHP 7.1 you can use:

$closure = Closure::fromCallable([$obj, 'myMethod'])

Since PHP 5.4 you can use:

$method = new ReflectionMethod($obj, 'myMethod'); $closure = $method->getClosure($obj);

But in your example, myMethod() accepts an argument, so this closure should be called like this:

$closure($msg)