//class 類別 
class demo {

//成員 hello()
 function hello(){
        echo 'Hello World!';
    }
 
//成員 hellome()
  function hellome(){
        echo 'Hello ME !';
    }
    
 //  public Hellohi(){        // 不能這樣用呀 !!
 //       echo 'Hello hi ';
 //   }
 
 public $engine = "300cc" ; // 可以這樣用 !! public , private , protected
 function car() {
    // echo $engine;      // 這變數無法使用 !!! $engine 不是全區 !! 要用 this
   echo $this->engine;    // $this 呼叫含其他函數
   }

 function car2() {
   echo $this->engine2 = "300cc" ;    // 這樣也可不必宣告 public
   }
   
   
   
}
$demo1 = new demo; //將class 實體化成 demo1 物件
$demo1 -> hello() ; // 呼叫 hello() ; 

$demo2 = new demo;  //將class 實體化成 demo2 物件
$demo1 -> hellome() ; // 呼叫 hellome() ; 

 ///////////////////////////////////////
 
class car{         // 類別 car 

    function Action(){
        $this->name; // 名字 是 public 可由Class 外部設定
        $this->_startEngine();
        $this->_clutch();
        $this->_transMission();
        $this->_accelerator();
    }
    
    private function _startEngine(){...}  
    private function _clutch(){...}
    private function _transMission(){...}
    private function _accelerator(){...}
}
    
$Acar -> new car
$Acar->name = 'A-CAR';
$Acar->Action() ; 

$Bcar -> new car
$Bcar->name = 'B-CAR';
$Bcar->Action() ; 
  

// 例如 class 類別 ==> 車啟動
// 實體化成 A車  物件 , B車 物件
// 啟動 A車 , 啟動 B車 

arrow
arrow
    文章標籤
    php class
    全站熱搜

    echochio 發表在 痞客邦 留言(0) 人氣()