Current Location: Home> Function Categories> spl_autoload_call

spl_autoload_call

Try to call all registered __autoload() functions to load the request class
Name:spl_autoload_call
Category:SPL
Programming Language:php
One-line Description:Try to call all registered __autoload() functions to load the requested class

Function name: spl_autoload_call()

Applicable version: PHP 5 >= 5.1.2, PHP 7

Function Description: The spl_autoload_call() function attempts to call all registered __autoload() functions to load the requested class.

Syntax: bool spl_autoload_call ( string $class_name )

parameter:

  • class_name: The class name that needs to be loaded.

Return value:

  • Return true when the class is successfully loaded.
  • Return false when no class is found or loading fails.

Notes:

  • The spl_autoload_call() function calls the registered __autoload() function in order in order of registration until the appropriate class is found.

Example:

 // 定义一个自动加载函数function my_autoload($class_name) { include $class_name . '.php'; } // 注册自动加载函数spl_autoload_register('my_autoload'); // 尝试加载类$result = spl_autoload_call('MyClass'); if ($result) { echo '类加载成功!'; } else { echo '类加载失败!'; }

In the above example, we first define an automatic loading function named my_autoload() , which dynamically contains the corresponding PHP file according to the class name. Then, we register the autoload function into the autoload queue through spl_autoload_register() function.

Next, we call spl_autoload_call() function to try to load a class named MyClass . If the class is loaded successfully, the output is "Class loaded successfully!", otherwise the output is "Class loaded failed!".

It should be noted that if no automatic loading function is registered or the corresponding class file is not found, spl_autoload_call() function will return false.

Similar Functions
Popular Articles