日期:2014-05-17 浏览次数:20588 次
class car { public $name; function __construct() { } public function showname() { echo 'name is '.$this-> name; } public function setname($name){ $this->name=$name; if ($this->name=='end'){ exit(); } } } $aaa=new car(); $aaa->setname('test1'); $aaa-> showname(); $bbb=new car(); $bbb->setname('end'); $bbb-> showname();
------解决方案--------------------
想了一下 你是要停止 而不是终止整个运行
class car { public $name; protected $goon; function __construct() { $this->goon=true; } public function showname() { if ($this->goon==true){ echo 'name is '.$this-> name; } } public function setname($name){ $this->name=$name; if ($this->name=='end'){ $this->goon=false; } } } $aaa=new car(); $aaa->setname('test1'); $aaa-> showname(); $bbb=new car(); $bbb->setname('end'); $bbb-> showname(); $bbb=new car(); $bbb->setname('ttt'); $bbb-> showname();