Requests::get_transport_class( array $capabilities = [] ): string
- Source
wp-includes/Requests/src/Requests.php:225
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
- Scaling
- Scales with input
- Instructions
- 14–38
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 41.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- serializeserialisation
serialize()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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–26 | ksort(), serialize() |
!isset($cap_string) && $class && $result === true | 35–38 | ksort(), serialize(), ::test() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 41 | 14–38 | 6 | |
| 8.5 | 41 | 14–38 | 6 | |
| 8.4 | 41 | 14–38 | 6 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 43 | 14–40 | 6 | |
| 8.2 | 43 | 14–40 | 6 | |
| 8.1 | 43 | 14–40 | 6 | |
| 7.4 | 43 | 14–40 | 6 |
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.
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.