WP_CLI\Utils

describe_callable()WP-CLI 1.0

Describe a callable as a string.

No Hooks.

Return

String. String description of the callable.

Usage

describe_callable( $callable );
$callable(callable) (required)
The callable to describe.

describe_callable() code WP-CLI 2.7.0-alpha

function describe_callable( $callable ) {
	try {
		if ( $callable instanceof Closure ) {
			$reflection = new ReflectionFunction( $callable );

			return "Closure in file {$reflection->getFileName()} at line {$reflection->getStartLine()}";
		}

		if ( is_array( $callable ) ) {
			if ( is_object( $callable[0] ) ) {
				return sprintf(
					'%s->%s()',
					get_class( $callable[0] ),
					$callable[1]
				);
			}

			return sprintf( '%s::%s()', $callable[0], $callable[1] );
		}

		return gettype( $callable );
	} catch ( Exception $exception ) {
		return 'Callable of unknown type';
	}
}