abstrait:<?php /* 手工添加腳本地址加載 * include'Car.php'; //include 'Mobile.php'; $car = new Car('奔馳','C200','250000元'); echo '您購(gòu)
<?php /* 手工添加腳本地址加載 * include'Car.php'; //include 'Mobile.php'; $car = new Car('奔馳','C200','250000元'); echo '您購(gòu)買(mǎi)的品牌:'.$car->brand,'; 型號(hào):'.$car->model,'; 價(jià)格:'.$car->price.'<hr>'; echo $car->study('php','類(lèi)','方法'); $mobile = new Mobile('華為','P20','5000元'); echo '您購(gòu)買(mǎi)的品牌:'.$mobile->brand,'; 型號(hào):'.$mobile->model,'; 價(jià)格:'.$mobile->price.'<hr>'; */ //自動(dòng)加載器函數(shù) 最重要的參數(shù)是回調(diào)(利用參數(shù)回調(diào)自動(dòng)加載) spl_autoload_register(function($className){ //推薦使用絕對(duì)路徑 __DIR__ 可以獲得當(dāng)前文件的絕對(duì)路徑 include __DIR__.'/'.$className.'.php'; }); $car = new Car('奔馳','C200','250000元'); echo '您購(gòu)買(mǎi)的品牌:'.$car->brand,'; 型號(hào):'.$car->model,'; 價(jià)格:'.$car->price.'<hr>'; echo $car->study('php','類(lèi)','方法'); $mobile = new Mobile('華為','P20','5000元'); echo '您購(gòu)買(mǎi)的品牌:'.$mobile->brand,'; 型號(hào):'.$mobile->model,'; 價(jià)格:'.$mobile->price.'<hr>';
腳本1代碼:
<?php
class Car
{
public $brand; //建立類(lèi)屬性
public $model;
public $price;
public function __construct($brand,$model,$price)
{
$this->brand = $brand; //建立構(gòu)造方法 初始化 類(lèi)屬性
$this->model = $model;
$this->price = $price;
}
public function study($brand,$model,$price)
{ //方法
return '我在使用'.$brand.'中的'.$model.'調(diào)用的'.$price.'<hr>';
}
}
腳本2的代碼:
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/3/24 0024
* Time: 16:13
*/
class Mobile
{
public $brand; //建立類(lèi)屬性
public $model;
public $price;
public function __construct($brand,$model,$price)
{
$this->brand = $brand; //建立構(gòu)造方法 初始化 類(lèi)屬性
$this->model = $model;
$this->price = $price;
}
}
Professeur correcteur:查無(wú)此人Temps de correction:2019-03-25 09:19:01
Résumé du professeur:完成的不錯(cuò),代碼寫(xiě)的也可以。下次可以說(shuō)說(shuō)自己的理解。老師能給你最好的建議。繼續(xù)加油。