亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

完成類的自動加載

asal 2019-04-22 21:24:56 212
abstrak:類的自動加載:在外部頁面中不需要引入“類文件”,但程序會在需要一個(gè)類的時(shí)候自動去“動態(tài)加載”該類。如① 創(chuàng)建一個(gè)對象的時(shí)候new② 直接使用一個(gè)類名(操作靜態(tài)屬性與方法)//Car.php <?php class Car {     public $brand;     public 

類的自動加載:在外部頁面中不需要引入“類文件”,但程序會在需要一個(gè)類的時(shí)候自動去“動態(tài)加載”該類。如

① 創(chuàng)建一個(gè)對象的時(shí)候new

② 直接使用一個(gè)類名(操作靜態(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ù)隊(duì)列中。
//也可以直接使用回調(diào)函數(shù)執(zhí)行自動加載
spl_autoload_register(function($classname){
include __DIR__.'\\'.$classname.'.php';
})
自動加載后就可以直接創(chuàng)建一個(gè)對象
$car=new Car('豐田','漢拉達(dá)','3500000');
echo $car->brand;
?>


Guru membetulkan:查無此人Masa pembetulan:2019-04-23 13:44:27
Rumusan guru:完成的不錯(cuò)。自動加載,現(xiàn)在很多框架都是這樣。繼續(xù)加油

Nota Keluaran

Penyertaan Popular