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
<