Php can be automatically loaded in two ways. For more information, see. Php supports two automatic loading methods.
The first scheme uses _ autoload, which is relatively simple and weak.
But there is a problem that cannot be solved, that is, to determine whether the file exists before include.
The code is as follows:
Set_include_path ('A'. PATH_SEPARATOR. get_include_path ());
Function _ autoload ($ className)
{
// If this check is added, because the file is not in the current directory, it will not detect the file,
// But the include operation is successful.
If (file_exists ($ className. '. php ')){
Include_once ($ className. '. php ');
} Else {
Exit ('No file ');
}
}
$ A = new Acls ();
The second method is to use spl for automatic loading.
Spl_autoload_register ()
A simple example
The code is as follows:
Set_include_path ('A'. PATH_SEPARATOR. get_include_path ());
// Function _ autoload ($ className)
//{
// If (file_exists ($ className. '. php ')){
// Include_once ($ className. '. php ');
//} Else {
// Exit ('No file ');
//}
/
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