Automattic\WooCommerce\Internal\Logging

SafeGlobalFunctionProxy::__callStatic()public staticWC 9.4.0

Proxy for trapping all calls on SafeGlobalFunctionProxy. Use this for calling WP and WC global functions safely. Example usage:

SafeGlobalFunctionProxy::wp_parse_url('https://example.com', PHP_URL_PATH);

Метод класса: SafeGlobalFunctionProxy{}

Хуков нет.

Возвращает

Разное. The result of the function call, or null if an error occurs.

Использование

$result = SafeGlobalFunctionProxy::__callStatic( $name, $arguments );
$name(строка) (обязательный)
The name of the function to call.
$arguments(массив) (обязательный)
The arguments to pass to the function.

Список изменений

С версии 9.4.0 Введена.

Код SafeGlobalFunctionProxy::__callStatic() WC 9.7.1

public static function __callStatic( $name, $arguments ) {
	// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler -- Custom error handler is necessary to convert errors to exceptions
	set_error_handler(
		static function ( int $type, string $message, string $file, int $line ) {
			if ( __FILE__ === $file ) {
				// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Used to adjust file and line number for accurate error reporting
				$trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 3 );
				$file  = $trace[2]['file'] ?? $file;
				$line  = $trace[2]['line'] ?? $line;
			}
			$sanitized_message = filter_var( $message, FILTER_SANITIZE_FULL_SPECIAL_CHARS );
			// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- $message sanitised above. we don't want to rely on esc_html since it's not a PHP built-in
			throw new \ErrorException( $sanitized_message, 0, $type, $file, $line );
		}
	);

	try {
		self::maybe_load_missing_function( $name );
		$results = call_user_func_array( $name, $arguments );
	} catch ( \Throwable $e ) {
		self::log_wrapper_error( $name, $e->getMessage(), $arguments );
		$results = null;
	} finally {
		restore_error_handler();
	}

	return $results;
}