<?php class FilterAssert { public static function boolean(callable $filter): void { switch ($filter) { case $filter instanceof Closure: $reflection = new ReflectionFunction($filter); break; case is_object($filter): $reflection = new ReflectionMethod($filter, '__invoke'); break; default: throw new InvalidArgumentException( sprintf('Expected Closure or invokable object on callable filter, %s given', gettype($filter)) ); } var_dump($reflection->getReturnType()); } } class A { public function b() {} } $filter = new class { public function __invoke(int $datum): bool { return $datum === 1; } }; FilterAssert::boolean($filter);
You have javascript disabled. You will not be able to edit any code.