abstrait:// public/Mobile.php <?php class Mobile { public $brand; //品牌 public $model; //型號 public
// public/Mobile.php <?php class Mobile { public $brand; //品牌 public $model; //型號 public $price; //價(jià)格 public function __construct($brand,$model,$price) { $this->brand = $brand; $this->model = $model; $this->price = $price; } } // demo3.php <?php spl_autoload_register(function($className){ require __DIR__.'/public/'.$className.'.php'; }); $mobile = new Mobile('小米','xiaomi9',7800); echo $mobile->brand.$mobile->model.':'.$mobile->price,'<br>';
自動(dòng)加載器spl_autoload_register()利用回調(diào)函數(shù)和絕對路徑字符串拼接實(shí)現(xiàn)自動(dòng)加載類,可以大大提升加載的效率。
Professeur correcteur:查無此人Temps de correction:2019-03-25 09:21:16
Résumé du professeur:完成的不錯(cuò)。這個(gè)截圖我好像看到過,又是你吧。繼續(xù)加油