abstrakt:類的自動加載:在外部頁面中不需要引入“類文件”,但程序會在需要一個類的時候自動去“動態(tài)加載”該類。如① 創(chuàng)建一個對象的時候new② 直接使用一個類名(操作靜態(tài)屬性與方法)//Car.php <?php class Car { public $brand; public 
類的自動加載:在外部頁面中不需要引入“類文件”,但程序會在需要一個類的時候自動去“動態(tài)加載”該類。如
① 創(chuàng)建一個對象的時候new
② 直接使用一個類名(操作靜態(tài)屬性與方法)
//Car.php <?php class Car { public $brand; public $model; public $price; public function __construct($brand,$model,$price){ $this->brand=$brand; $this->model=$model; $this->price=$price; } } ?> //text.php <?php function my_autoload($classname){ $filename=__DIR__.'\\'.$classname.'.php'; include_once($filename); } spl_autoload_register('my_autoload');//將函數(shù)注冊到SPL的__autoload的 函數(shù)隊列中。 //也可以直接使用回調(diào)函數(shù)執(zhí)行自動加載 spl_autoload_register(function($classname){ include __DIR__.'\\'.$classname.'.php'; }) 自動加載后就可以直接創(chuàng)建一個對象 $car=new Car('豐田','漢拉達(dá)','3500000'); echo $car->brand; ?>
Korrigierender Lehrer:查無此人Korrekturzeit:2019-04-23 13:44:27
Zusammenfassung des Lehrers:完成的不錯。自動加載,現(xiàn)在很多框架都是這樣。繼續(xù)加油