Spl_autoload_register and __autoload Auto CAD video tutorial Grand Theft Auto Cheats auto cad201

Source: Internet
Author: User
About Spl_autoload_register () and __autoload ()

Look at the use of both:

__autoload usage function __autoload ($classname) {$filename = "./class/". $classname. ". Class.php "; if (Is_file ($filename)) {include $filename;}}
Spl_autoload_register usage spl_autoload_register (' load_class ');
function Load_class ($classname) {$filename = "./class/". $classname. ". Class.php "; if (Is_file ($filename)) {include $filename;}}

The benefits of using Spl_autoload_register () are ineffable: (1) automatic loading of objects is more convenient, and many frameworks do this:

Class Classautoloader {public Function __construct () {spl_autoload_register (Array ($this, ' loader '));} Private function Loader ($className) {echo ' Trying to load ', $className, ' via ', __method__, ' () \ n '; include $className. '. php '; } }
$autoloader = new Classautoloader ();
$obj = new Class1 (); $obj = new Class2 ();

(2) You should know that the __autoload () function can only exist once, spl_autoload_register () can of course register multiple functions

function A () {include ' a.php ';} function B () {include ' b.php ';} spl_autoload_register (' a '); Spl_autoload_register (' B ');

(3) The SPL function is very rich, providing more functions, such as spl_autoload_unregister () logout of registered functions, Spl_autoload_functions () return all registered functions, etc.

The above describes the Spl_autoload_register and __autoload, including the register,auto aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.