public static function assertMethodName($methodName, $callee, $parameterPosition) { if (!is_string($methodName)) { throw new static(sprintf('%s() expects parameter %d to be string, %s given', $callee, $parameterPosition, gettype($methodName))); } }
/** * Returns a function that invokes method `$method` with arguments `$methodArguments` on the object * * @param string $methodName * @param array $arguments * @return callable */ function invoker($methodName, array $arguments = []) { InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 1); return static function ($object) use($methodName, $arguments) { return $object->{$methodName}(...$arguments); }; }