Home > Backend Development > PHP Tutorial > 小弟我有有关问题

小弟我有有关问题

WBOY
Release: 2016-06-13 13:08:44
Original
943 people have browsed it

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

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

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

$p->name();
$p->age();
$p->talk();

$x = new xiaoli("xiaoli");
$x->age();
$x->name();
$x->talk();


Copy after login


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

既然你使用了接口,那么 name 和 age 就应该不暴露给外界
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template