国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

獨(dú)立完成類的自動加載案例,從此告別include/require

Original 2019-05-21 11:33:50 185
abstract:shop.php<?php/** * Created by PhpStorm. * User: Administrator * Date: 2019/5/21 * Time: 11:11 */class  Shop{    public  $name;    public  $price;    pub

shop.php


<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/5/21
* Time: 11:11
*/

class  Shop
{
   public  $name;
   public  $price;
   public  $catid;
   public  $lei='shop';

   public  function __construct($name,$price,$catid)
   {
       $this->name=$name;
       $this->price=$price;
       $this->catid=$catid;
   }

   function  getDetail(){
       return '商品名稱'.$this->name."<br>".'商品價(jià)格'.':'.$this->price.'<br>'.'商品分類'.":".$this->catid;
   }
}





car.php


<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/5/21
* Time: 11:11
*/

class  Car
{
   public  $name;
   public  $price;
   public  $catid;
   public  $lei='car';


   public  function __construct($name,$price,$catid)
   {
       $this->name=$name;
       $this->price=$price;
       $this->catid=$catid;
   }

   function  getDetail(){
       return '商品名稱'.$this->name."<br>".'商品價(jià)格'.':'.$this->price.'<br>'.'商品分類'.":".$this->catid;
   }
}



new.php 

<?php
header("Content-type: text/html; charset=utf-8");
date_default_timezone_set("PRC");

spl_autoload_register(function ($className){
   include  __DIR__.'/commonClass/'.$className.'.php';
});

$shop = new Shop('上衣',23,'服裝');
echo  $shop->getDetail(),'<br>';
echo  $shop->lei;echo "<br>";



$car = new Car('大眾','30萬','奔騰');
echo  $car->getDetail();echo "<br>";
echo $car->lei;




?>

Correcting teacher:查無此人Correction time:2019-05-22 09:16:22
Teacher's summary:完成的不錯(cuò),學(xué)習(xí)完類,就相當(dāng)于php入門了。繼續(xù)加油。

Release Notes

Popular Entries