From df808fc42d626befe550dc1262dc9f6f3e2d460b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 28 Jul 2017 01:15:52 +0000 Subject: [PATCH] General: Move the `__autoload()` compat function into its own file to prevent deprecated notices being thrown by the compiler in PHP 7.2. The `__autoload()` function is deprecated in PHP 7.2, which means WordPress' own `__autoload()` compat function for PHP 5.2 needs to be moved into a separate file to prevent the PHP 7.2 compiler from complaining. Props ayeshrajans See #40109 Built from https://develop.svn.wordpress.org/trunk@41178 git-svn-id: http://core.svn.wordpress.org/trunk@41018 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/compat.php | 99 +++------------------------ wp-includes/spl-autoload-compat.php | 100 ++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 110 insertions(+), 91 deletions(-) create mode 100644 wp-includes/spl-autoload-compat.php diff --git a/wp-includes/compat.php b/wp-includes/compat.php index 0ccee2d498..7e37c30762 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -488,93 +488,12 @@ if ( ! function_exists( 'array_replace_recursive' ) ) : } endif; -// SPL can be disabled on PHP 5.2 -if ( ! function_exists( 'spl_autoload_register' ) ): - $_wp_spl_autoloaders = array(); - - /** - * Autoloader compatibility callback. - * - * @since 4.6.0 - * - * @param string $classname Class to attempt autoloading. - */ - function __autoload( $classname ) { - global $_wp_spl_autoloaders; - foreach ( $_wp_spl_autoloaders as $autoloader ) { - if ( ! is_callable( $autoloader ) ) { - // Avoid the extra warning if the autoloader isn't callable. - continue; - } - - call_user_func( $autoloader, $classname ); - - // If it has been autoloaded, stop processing. - if ( class_exists( $classname, false ) ) { - return; - } - } - } - - /** - * Registers a function to be autoloaded. - * - * @since 4.6.0 - * - * @param callable $autoload_function The function to register. - * @param bool $throw Optional. Whether the function should throw an exception - * if the function isn't callable. Default true. - * @param bool $prepend Whether the function should be prepended to the stack. - * Default false. - */ - function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { - if ( $throw && ! is_callable( $autoload_function ) ) { - // String not translated to match PHP core. - throw new Exception( 'Function not callable' ); - } - - global $_wp_spl_autoloaders; - - // Don't allow multiple registration. - if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) { - return; - } - - if ( $prepend ) { - array_unshift( $_wp_spl_autoloaders, $autoload_function ); - } else { - $_wp_spl_autoloaders[] = $autoload_function; - } - } - - /** - * Unregisters an autoloader function. - * - * @since 4.6.0 - * - * @param callable $function The function to unregister. - * @return bool True if the function was unregistered, false if it could not be. - */ - function spl_autoload_unregister( $function ) { - global $_wp_spl_autoloaders; - foreach ( $_wp_spl_autoloaders as &$autoloader ) { - if ( $autoloader === $function ) { - unset( $autoloader ); - return true; - } - } - - return false; - } - - /** - * Retrieves the registered autoloader functions. - * - * @since 4.6.0 - * - * @return array List of autoloader functions. - */ - function spl_autoload_functions() { - return $GLOBALS['_wp_spl_autoloaders']; - } -endif; +/** + * Polyfill for the SPL autoloader. In PHP 5.2 (but not 5.3 and later), SPL can + * be disabled, and PHP 7.2 raises notices if the compiler finds an __autoload() + * function declaration. Function availability is checked here, and the + * autoloader is included only if necessary. + */ +if ( ! function_exists( 'spl_autoload_register' ) ) { + require_once ABSPATH . WPINC . '/spl-autoload-compat.php'; +} diff --git a/wp-includes/spl-autoload-compat.php b/wp-includes/spl-autoload-compat.php new file mode 100644 index 0000000000..599b6046b3 --- /dev/null +++ b/wp-includes/spl-autoload-compat.php @@ -0,0 +1,100 @@ +