llms_get_callable_name( mixed $callable )

Retrieve a string representing a PHP callable


Description Description

This can be used to log callables regardless of the callable format.


Top ↑

Parameters Parameters

$callable

(mixed) (Required) PHP callable.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/functions/llms.functions.log.php

function llms_get_callable_name( $callable ) {

	// Function name or static class -> method: 'function' or 'class::method'.
	if ( is_string( $callable ) ) {
		return $callable;
	}

	if ( is_array( $callable ) && ! empty( $callable ) ) {

		// Class and class method: [ $class, 'method' ]. (phpcs:ignore Squiz.PHP.CommentedOutCode.Found).
		if ( is_object( $callable[0] ) ) {
			return get_class( $callable[0] ) . '->' . $callable[1];
		}

		// Static class + method: [ 'class', 'method' ]. (phpcs:ignore Squiz.PHP.CommentedOutCode.Found).
		return implode( '::', $callable );

	}

	// Invokable class: $class. (phpcs:ignore Squiz.PHP.CommentedOutCode.Found).
	if ( is_object( $callable ) ) {
		return get_class( $callable );
	}

	return 'Unknown';

}


Top ↑

Changelog Changelog

Changelog
Version Description
5.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.