wppaste
WordPress

Autoload::load( string $class_name ): bool

Source
wp-includes/Requests/src/Autoload.php:131
Autoloader.

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

$class_namestring
Name of the class name to load.

Return value

bool
Whether a class was loaded or not.

Performance profile

How much work a call to Autoload::load() 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
Heavy

Reads or writes the filesystem via file_exists().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
12–54

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

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

  • filesystemfilesystem accessfile_exists()called directly

What one call costs · 7 distinct outcomes

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

WhenInstructionsCalls it makes
$psr_4_prefix_pos !== 012stripos()
!isset($file) && !isset($class_lower)23–31stripos(), strtolower()
isset($file)25–35stripos(), strtolower(), file_exists()
!isset($file) && isset($class_lower) && defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')35–43stripos(), strtolower(), class_alias()
!isset($file) && isset($class_lower)38–50stripos(), strtolower(), trigger_error(), class_alias()
isset($file) && !file_exists() && isset($class_lower) && defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')39–47stripos(), strtolower(), file_exists(), class_alias()
isset($file) && !file_exists() && isset($class_lower)42–54stripos(), strtolower(), file_exists(), trigger_error(), class_alias()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6212–5410
8.56212–5410
8.46212–54107 fewer instructions than PHP 8.3
8.36915–6310
8.26915–6310
8.16915–6310
7.46915–6310

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.

Uses · 1

Source code

		public static function load($class_name) {			// Check that the class starts with "Requests" (PSR-0) or "WpOrg\Requests" (PSR-4).			$psr_4_prefix_pos = strpos($class_name, 'WpOrg\\Requests\\'); 			if (stripos($class_name, 'Requests') !== 0 && $psr_4_prefix_pos !== 0) {				return false;			} 			$class_lower = strtolower($class_name); 			if ($class_lower === 'requests') {				// Reference to the original PSR-0 Requests class.				$file = dirname(__DIR__) . '/library/Requests.php';			} elseif ($psr_4_prefix_pos === 0) {				// PSR-4 classname.				$file = __DIR__ . '/' . strtr(substr($class_name, 15), '\\', '/') . '.php';			} 			if (isset($file) && file_exists($file)) {				include $file;				return true;			} 			/*			 * Okay, so the class starts with "Requests", but we couldn't find the file.			 * If this is one of the deprecated/renamed PSR-0 classes being requested,			 * let's alias it to the new name and throw a deprecation notice.			 */			if (isset(self::$deprecated_classes[$class_lower])) {				/*				 * Integrators who cannot yet upgrade to the PSR-4 class names can silence deprecations				 * by defining a `REQUESTS_SILENCE_PSR0_DEPRECATIONS` constant and setting it to `true`.				 * The constant needs to be defined before the first deprecated class is requested				 * via this autoloader.				 */				if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS') || REQUESTS_SILENCE_PSR0_DEPRECATIONS !== true) {					// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error					trigger_error(						'The PSR-0 `Requests_...` class names in the Requests library are deprecated.'						. ' Switch to the PSR-4 `WpOrg\Requests\...` class names at your earliest convenience.',						E_USER_DEPRECATED					); 					// Prevent the deprecation notice from being thrown twice.					if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) {						define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);					}				} 				// Create an alias and let the autoloader recursively kick in to load the PSR-4 class.				return class_alias(self::$deprecated_classes[$class_lower], $class_name, true);			} 			return false;		}

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/Autoload.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.