wppaste
WordPress

Requests::get_transport_class( array $capabilities = [] ): string

Source
wp-includes/Requests/src/Requests.php:225
Get the fully qualified class name (FQCN) for a working transport.

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$capabilitiesarrayoptional
Default: []

Return value

string
FQCN of the transport to use, or an empty string if no transport was found which provided the requested capabilities.

Performance profile

How much work a call to Requests::get_transport_class() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
14–38

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 41.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • serializeserialisationserialize()called directly

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost Requests::get_transport_class() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always14–26ksort(), serialize()
!isset($cap_string) && $class && $result === true35–38ksort(), serialize(), ::test()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4114–386
8.54114–386
8.44114–3862 fewer instructions than PHP 8.3
8.34314–406
8.24314–406
8.14314–406
7.44314–406

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Source code

	protected static function get_transport_class(array $capabilities = []) {		// Caching code, don't bother testing coverage.		// @codeCoverageIgnoreStart		// Array of capabilities as a string to be used as an array key.		ksort($capabilities);		$cap_string = serialize($capabilities); 		// Don't search for a transport if it's already been done for these $capabilities.		if (isset(self::$transport[$cap_string])) {			return self::$transport[$cap_string];		} 		// Ensure we will not run this same check again later on.		self::$transport[$cap_string] = '';		// @codeCoverageIgnoreEnd 		if (empty(self::$transports)) {			self::$transports = self::DEFAULT_TRANSPORTS;		} 		// Find us a working transport.		foreach (self::$transports as $class) {			if (!class_exists($class)) {				continue;			} 			$result = $class::test($capabilities);			if ($result === true) {				self::$transport[$cap_string] = $class;				break;			}		} 		return self::$transport[$cap_string];	}

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/Requests/src/Requests.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.