类和对象的介绍 //定义类 class Computer{ /* public 公有的 private 私有 protected 受保护的命运2太贵了怎么办 属性 */ public $cpu ="amd 5000"; protected $mainboard ="华硕9000x"; private $hd =279; //方法 public f
//定义类 class Computer{ /* public 公有的 private 私有 protected 受保护的命运2太贵了怎么办 属性 */ public $cpu ="amd 5000"; protected $mainboard ="华硕9000x"; private $hd =279; //方法 public function game($gameName=''){ if($this->MY()<300){ echo "命运2太贵了 要279RMB"; return false; //终止 } return true; //执行 } public function job($word='工作'){ echo ($this->game()); } public function MY(){ return ($this->hd); } } //对象实例化 $computer =new Computer(); // var_dump($computer->mainboard);//无法访问 是私有的 //var_dump($computer->cpu); $computer->game();