name="hello"; } public function __s">
时间:2021-07-01 10:21:17 帮助过:22人阅读
class P{ private $name=""; function __construct(){ $this->name="hello"; } public function __set($name, $value){ $this->$name=$value; } public function showName(){ echo $this->name; }}
class C extends P{ function __construct(){ parent::__construct(); //想在这里给P类的$name换个值(你好)怎么做? } }
class P{ private $name=""; function __construct(){ $this->name="hello"; } public function __set($name, $value){ $this->$name=$value; } public function showName(){ echo $this->name; }}class C extends P{ function __construct(){ parent::__construct(); $this->name = '你好'; } }$c=new C;$c->showName();print_r($c);你好
class P{ private $name=""; function __construct(){ $this->name="hello"; } public function __set($name, $value){ $this->$name=$value; } public function showName(){ echo $this->name; }}class C extends P{ function __construct(){ parent::__construct(); //想在这里给P类的$name换个值(你好)怎么做? $this->name = '你好'; }}$obj = new C();$obj->showName();