独立完成类的自动加载案例

Original 2019-04-14 20:34:26 251
abstract:<?php //自动加载器:最重要的一个参数就是一个回调 spl_autoload_register(function($className){     //推荐使用绝对路径     include __DIR__.'\..\chapter_04\public\\'.$className
<?php
//自动加载器:最重要的一个参数就是一个回调
spl_autoload_register(function($className){
    //推荐使用绝对路径
    include __DIR__.'\..\chapter_04\public\\'.$className.'.php';
});
$mobile=new Mobile('华为','P20','7200');
echo $mobile->brand.$mobile->model.':'.$mobile->price,'<br>';


Correcting teacher:天蓬老师Correction time:2019-04-14 21:11:20
Teacher's summary:当脚本 中的引用的外部类较多时, 大量的include会影响到代码的执行效率,都过自动加载, 可以极大的方便用户

Release Notes

Popular Entries