Changeset 45637
- Timestamp:
- 07/15/2019 05:10:36 AM (5 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/compat.php
r45636 r45637 450 450 } 451 451 452 /**453 * Polyfill for the SPL autoloader. In PHP 5.2 (but not 5.3 and later), SPL can454 * be disabled, and PHP 7.2 raises notices if the compiler finds an __autoload()455 * function declaration. Function availability is checked here, and the456 * autoloader is included only if necessary.457 */458 if ( ! function_exists( 'spl_autoload_register' ) ) {459 require_once ABSPATH . WPINC . '/spl-autoload-compat.php';460 }461 462 452 if ( ! function_exists( 'is_countable' ) ) { 463 453 /** -
trunk/src/wp-includes/spl-autoload-compat.php
r41178 r45637 6 6 * See https://core.trac.wordpress.org/ticket/41134 7 7 * 8 * @deprecated 5.3.0 No longer needed as the minimum PHP requirement has moved beyond PHP 5.3. 9 * 8 10 * @package PHP 9 11 * @access private 10 12 */ 11 13 12 if ( ! function_exists( 'spl_autoload_register' ) ) { 13 $_wp_spl_autoloaders = array(); 14 15 /** 16 * Autoloader compatibility callback. 17 * 18 * @since 4.6.0 19 * 20 * @param string $classname Class to attempt autoloading. 21 */ 22 function __autoload( $classname ) { 23 global $_wp_spl_autoloaders; 24 foreach ( $_wp_spl_autoloaders as $autoloader ) { 25 if ( ! is_callable( $autoloader ) ) { 26 // Avoid the extra warning if the autoloader isn't callable. 27 continue; 28 } 29 30 call_user_func( $autoloader, $classname ); 31 32 // If it has been autoloaded, stop processing. 33 if ( class_exists( $classname, false ) ) { 34 return; 35 } 36 } 37 } 38 39 /** 40 * Registers a function to be autoloaded. 41 * 42 * @since 4.6.0 43 * 44 * @param callable $autoload_function The function to register. 45 * @param bool $throw Optional. Whether the function should throw an exception 46 * if the function isn't callable. Default true. 47 * @param bool $prepend Whether the function should be prepended to the stack. 48 * Default false. 49 */ 50 function spl_autoload_register( $autoload_function, $throw = true, $prepend = false ) { 51 if ( $throw && ! is_callable( $autoload_function ) ) { 52 // String not translated to match PHP core. 53 throw new Exception( 'Function not callable' ); 54 } 55 56 global $_wp_spl_autoloaders; 57 58 // Don't allow multiple registration. 59 if ( in_array( $autoload_function, $_wp_spl_autoloaders ) ) { 60 return; 61 } 62 63 if ( $prepend ) { 64 array_unshift( $_wp_spl_autoloaders, $autoload_function ); 65 } else { 66 $_wp_spl_autoloaders[] = $autoload_function; 67 } 68 } 69 70 /** 71 * Unregisters an autoloader function. 72 * 73 * @since 4.6.0 74 * 75 * @param callable $function The function to unregister. 76 * @return bool True if the function was unregistered, false if it could not be. 77 */ 78 function spl_autoload_unregister( $function ) { 79 global $_wp_spl_autoloaders; 80 foreach ( $_wp_spl_autoloaders as &$autoloader ) { 81 if ( $autoloader === $function ) { 82 unset( $autoloader ); 83 return true; 84 } 85 } 86 87 return false; 88 } 89 90 /** 91 * Retrieves the registered autoloader functions. 92 * 93 * @since 4.6.0 94 * 95 * @return array List of autoloader functions. 96 */ 97 function spl_autoload_functions() { 98 return $GLOBALS['_wp_spl_autoloaders']; 99 } 100 } 14 _deprecated_file( basename( __FILE__ ), '5.3.0', null, 'SPL can no longer be disabled as of PHP 5.3.' );
Note: See TracChangeset
for help on using the changeset viewer.