类的自动加载案例

Original 2019-04-18 18:58:34 237
abstract:class Mobile {     public $brand; //品牌     public $model; //型号     public $price; //价格   
class Mobile

{

    public $brand; //品牌

    public $model; //型号

    public $price; //价格


    public function __construct($brand, $model, $price)

    {

        $this->brand = $brand;

        $this->model = $model;

        $this->price = $price;

    }

}


spl_autoload_register(function ($className) {

    require __DIR__ . '/public/' . $className . '.php';

});

$mobile = new Mobile('vivo', 'nex S', 5800);

echo $mobile->brand . $mobile->model . ':' . $mobile->price, '<br>';


Correcting teacher:查无此人Correction time:2019-04-19 09:20:59
Teacher's summary:完成的不错。类自动加载,减少代码量,也增加运行速度。继续加油

Release Notes

Popular Entries