Home  >  Article  >  Backend Development  >  小弟我有有关问题

小弟我有有关问题

WBOY
WBOYOriginal
2016-06-13 10:53:11783browse

我有问题求助
刚接触PHP ,写了如下的一小段,$x->name();为什么打印出来是空啊?

PHP code
interface man{    function talk();}abstract class person{    abstract function name();    abstract function age();    var $c="这是一个抽象类
";}class xiaoming extends person implements man { function name(){ echo ("xiaoming
"); } function age(){ echo ("12"."
"); } function talk(){ echo ("love
"); }}class xiaoli extends person implements man{ var $mingzi; function _construct($mingzi){ $this->mingzi=$mingzi; } function name(){ echo ($this->mingzi."
"); } function age(){ echo ("13
"); } function talk(){ echo ("you"); }}$p = new xiaoming();$p->name();$p->age();$p->talk();$x = new xiaoli("xiaoli");$x->age();$x->name();$x->talk();


------解决方案--------------------
__construct
------解决方案--------------------
__construct 双下划线

既然你使用了接口,那么 name 和 age 就应该不暴露给外界
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn