Home >Backend Development >PHP Tutorial >Yii source code interpretation-class automatic loading
To implement
Yii’s automatic class loading, it relies on PHP’s spl_autoload_register()
. Register an own autoloading function (autoloader) and insert it into the front of the autoloading function stack to ensure that Yii’s autoloader will be loaded first. transfer.
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
First load the third-party autoloader, and then load Yii's autoloader.
Last load Yii's autoloader, which ensures that Yii is loaded first.
Yii.php
can view the call of the autoloader code, which registers BaseYii::autoload()
as an autoloader.
The classes.php
called in it contains all core classes.
Reference
http://www.digpage.com/autoload.html
The above introduces Yii source code interpretation - automatic class loading, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.