Sadly, your comparison is incorrect.
// The equivalent to
$cl1 = Closure::fromCallable("getName");
$cl1 = $cl1->bindTo($bob, 'A');
// is most likely this
$cl2 = function() {
return call_user_func_array("getName", func_get_args());
};
$cl2 = $cl2->bindTo($bob, 'A');
Executing one or the other Closure should result in the same access violation error you already postet.
----
A simple PHP 7.0 polyfill could look like this:
----
namespace YourPackage;
/**
* Class Closure
*
* @see \Closure
*/
class Closure
{
/**
* @see \Closure::fromCallable()
* @param callable $callable
* @return \Closure
*/
public static function fromCallable(callable $callable)
{
// In case we've got it native, let's use that native one!
if(method_exists(\Closure::class, 'fromCallable')) {
return \Closure::fromCallable($callable);
}
return function () use ($callable) {
return call_user_func_array($callable, func_get_args());
};
}
}