3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in /in/D69oU on line 15
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: __autoload() is deprecated, use spl_autoload_register() instead in /in/D69oU on line 15 string(14) "class-yolo.php" string(12) "inc/YOLO.php" bool(false)
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.3.32 - 7.3.33
string(14) "class-yolo.php" string(12) "inc/YOLO.php" bool(false)
Output for 5.0.0 - 5.0.5
string(14) "using polyfill" string(14) "class-yolo.php" string(12) "inc/YOLO.php" bool(false)
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/D69oU on line 37
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/D69oU on line 37
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/D69oU on line 37
Process exited with code 255.

preferences:
299.36 ms | 401 KiB | 453 Q