<?php
if ( ! isset( $spl_autoloaders ) ) {
$spl_autoloaders = array();
}
if ( ! function_exists( 'spl_autoload_register' ) ):
var_dump( 'using polyfill' );
/**
* Autoloader compatibility callback.
*
* @param string $classname Class to attempt autoloading.
*/
function __autoload( $classname ) {
global $spl_autoloaders;
foreach ( $spl_autoloaders as $autoloader ) {
call_user_func( $autoloader, $classname );
// If it has been autoloaded, stop processing.
if ( class_exists( $classname, false ) ) {
return;
}
}
}
/**
* Register a function to be autoloaded.
*
* @param callable $autoload_function The function to register.
* @param boolean $throw Should the function throw an exception if the function isn't callable?
* @param boolean $prepend Should we prepend the function to the stack?
*/
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 $spl_autoloaders;
// Don't allow multiple registration.
if ( in_array( $autoload_function, $spl_autoloaders ) ) {
return;
}
if ( $prepend ) {
array_unshift( $spl_autoloaders, $autoload_function );
} else {
$spl_autoloaders[] = $autoload_function;
}
}
/**
* Unregister an autoloader function.
*
* @param callable $function The function to unregister.
* @return boolean True if the function was unregistered, false if it could not be.
*/
function spl_autoload_unregister( $function ) {
global $spl_autoloaders;
foreach ( $spl_autoloaders as &$autoloader ) {
if ( $autoloader === $function ) {
unset( $autoloader );
return true;
}
}
return false;
}
/**
* Get the registered autoloader functions.
*
* @return array List of autoloader functions.
*/
function spl_autoload_functions() {
return $GLOBALS['spl_autoloaders'];
}
endif;
function my_autoloader( $class ) {
$path = str_replace( '_', '-', $class );
$path = 'class-' . strtolower( $path ) . '.php';
var_dump( $path );
}
spl_autoload_register( 'my_autoloader' );
spl_autoload_register( 'my_autoloader' );
function my_autoloader2( $class ) {
$path = str_replace( '_', '/', $class );
$path = 'inc/' . $path . '.php';
var_dump( $path );
}
spl_autoload_register( 'my_autoloader2' );
var_dump( class_exists( 'YOLO' ) );
- Output for git.master, git.master_jit, rfc.property-hooks
- Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /in/D69oU on line 15
Process exited with code 255.
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
preferences:
31.76 ms | 405 KiB | 5 Q