abstrait://test.php <?php //類的自動加載 $getMyClass =function($className){ include(__DIR__."/demo/".$className.".php"); }; spl
//test.php <?php //類的自動加載 $getMyClass =function($className){ include(__DIR__."/demo/".$className.".php"); }; spl_autoload_register($getMyClass); $myGood = new Good(); $myGood->myEcho(); ?> ///demo/Good.php <?php class Good { public function myEcho(){ echo "GOOD 的 myEcho 方法"; } }
總結(jié):自定義一個閉包實現(xiàn)include類文件,把閉包作為參數(shù)傳給tpl_autoload_register方法。
new 一個對象時,自動調(diào)用tpl_autoload_register方法->調(diào)用自定義閉包函數(shù)->引入類文件。
Professeur correcteur:查無此人Temps de correction:2019-06-17 09:34:12
Résumé du professeur:完成的不錯。學(xué)完php的類以后,就算入門了,后面要多練習(xí)數(shù)據(jù)庫的增刪查改。繼續(xù)加油。