php--class privae
发布日期:2021-05-06 21:10:02 浏览次数:16 分类:原创文章

本文共 670 字,大约阅读时间需要 2 分钟。

<span>people class interface</span><hr><?php//声明类class people6{    //私有属性    private $name = '';    private $age = 0;    //构造函数    function __construct($name,$age)    {        $this->name = $name;        $this->age = $age;    }    //输出函数,函数内部可以读取私有成员变量,也可以读取私有函数    function introduce()    {        return "my name is {$this->name} , i am {$this->get_age()} years old.";    }    //公有函数    function get_name()    {        return $this->name;    }    //私有函数    private function get_age()    {        return $this->age;    }}//实例化$p1 = new people6('xia mi da wang',88);//调用输出函数echo $p1->introduce();echo "<br>";//调用公有函数echo $p1->get_name();//调用私有函数,出错//echo $p1->get_age();

 

上一篇:php--class static
下一篇:php--spry框架制作级联下拉菜单

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2025年03月29日 00时28分32秒