Home>Article>Backend Development> About loading classes in PHP
Object-oriented is an important idea, and classes are also important concepts in object-oriented, but class loading is the key to using classes.
There are two ways to access classes:
Access through instantiated objects
Access to class members
The prerequisite for access is that there is a class in the memory, so the class needs to be loaded into the memory in advance.
1. Manual loading
//类文件 Salary.php
应用文件:useSalary.php Student(); ?>
2. Automatic loading
The automatic loading mechanism used before PHP7: Use the __autoload() function provided by the system. Then when the system needs to use the class and it does not exist in the memory, the system will automatically call the __autoload() function to load the class file. .
//若在不同路径下
After PHP7, it is not recommended to use the __autoload() function, but to use a registration mechanism to customize the user The function is placed inside the system and uses spl_autoload_register (defined function).
//可以定义多个方法
Recommended:php tutorial
The above is the detailed content of About loading classes in PHP. For more information, please follow other related articles on the PHP Chinese website!