When other installed packages require Composer's autoloader, this file get's included. The core of WP-CLI doesn't autoload anything unless the binary is called. The classes WP_CLI_Command and WP_CLI aren't available and leads to a fatal error
PHP Fatal error: Class 'WP_CLI_Command' not found in [ABSPATH]/vendor/x-team/wp-cli-ssh/wp-cli-ssh.php on line 31
When inside a WP-CLI command, during the bootstrap, it defines 'WP_CLI_ROOT' here or here. By testing for that constant and returning early, the fatal error can be prevented.
Since in the
composer.json
the autoload is set to files, it gets loaded in memory for every time Composer sets up autoload.When other installed packages require Composer's autoloader, this file get's included. The core of WP-CLI doesn't autoload anything unless the binary is called. The classes
WP_CLI_Command
andWP_CLI
aren't available and leads to a fatal errorWhen inside a WP-CLI command, during the bootstrap, it defines 'WP_CLI_ROOT' here or here. By testing for that constant and returning early, the fatal error can be prevented.