"; /////////////////////////////////////////// echo "// 簡易物件變數宣告
"; echo "member:用var取代public
"; echo "function:不需要寫public
"; ///////////////////////////////////////////////////////////// echo "

"; //////標準寫法///////////////////////////////////////////// class webpage{ var $title; var $bgcolor; var $txtcolor; var $h1txt; function __construct($a1="標題",$a2="white",$a3="black",$a4="測試"){ $this->title = $a1; $this->bgcolor = $a2; $this->txtcolor = $a3; $this->h1txt = $a4; } function __destruct(){ $this->title = NULL; $this->bgcolor = NULL; $this->txtcolor = NULL; $this->h1txt = NULL; } function show(){ $str = "".$this->title."

".$this->h1txt."

"; echo $str; } } ////////////////////////////////////////////////// //$myweb = new webpage("網頁物件","gray","purple","物件變數的宣告與呼叫"); //$myweb = new webpage("新年祝福","blue","white","心想事成,事事如意"); $myweb = new webpage("生日祝福","pink","darkgreen","福如東海,壽比南山"); $myweb->show(); ?>