New PHP5 feature __autoload-PHP source code

Source: Internet
Author: User
Ec (2); since PYTHON was created in China (www.okpython.com) and promoted in PYTHON, it has never been time to study the features of PHP5. Now it is time. Today, let's talk about the function of the _ autoload function: Note: class files are automatically loaded to this file. When we use PHP4, the general process of using a class should be like this: loading require (class. php) or include (class. php) $ testnew class name and then use the class "script" ec (2); "script"


Since PYTHON was created in China (www.okpython.com) and promoted in PYTHON, there is no time to study the features of PHP5. Now it is time.
Let's talk about the functions of the _ autoload function today:
Note: class files are automatically loaded to this file.
When we use PHP4, the general process of using classes should be as follows:
Class File Load require (class. php)
Or include (class. php)
$ Test = new Class Name
Then use the class method.
Php5 is no longer needed, because PHP5 provides a simple and convenient method, that is, autoload
Examples:

Test. php files (used and automatically loaded)
Code: Class test {// class start
Function echo_str () {print "this is test files ";}

} // End of the class
?>
Testone. php file
Code: $ A = new test;
$ A-> echo_str ();
Function _ autoload (strtolower ($ className) {// strtolower is automatically converted to lower-case letters (of course, you can skip strtolower because php5 will automatically convert it to lower-case letters)
Require_once ($ className. ". php"); // automatically load the class file and give the file name (that is, the loading rule) according to the class name)
}
?>
Run testone. php, output "this is test files"
The original article in this article, if reproduced, please indicate the source. python China www.okpython.com

<

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.