PHP class auto-loading mechanism
Automatic loading of php:
Before php5, if we want to use a certain class or class method, it must include or require before it can be used. Every time a class is used, an include needs to be written, which is troublesome
php author To make it simple, it is best to reference a class. If there is no include currently, the system can automatically find the class and automatically introduce it~
So: the __autoload() function came into being.
Usually placed in the application entry class, such as discuz, placed in class_core.php.
Let’s talk about a simple example first:
The first case: the content of file A.php is as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
The second case: Sometimes I hope to customize autoload and want to give a cooler name for loader, then C .php is changed to the following:
1 2 3 4 5 6 7 8 9 10 11 |
|
The third situation: I hope to be more advanced and use a class to manage automatic loading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
This is currently the best form.
Usually we put spl_autoload_register(*) in the entry script, that is, quoted from the beginning. For example, the method of discuz below.
1 2 3 4 5 6 7 |
|
It’s great to put this paragraph at the front of the entry file~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
