php在对象之外访问其私有属性private及保护属性protected的特例

来源:互联网 发布:sql约束表达式大全 编辑:程序博客网 时间:2024/06/06 03:26

代码如下,在这种情况下php允许访问私有及保护属性:

class yunke{    protected $a = 55;    private $b = 66;    public function merge()    {        $result = clone $this;        $result->a=88;        $result->b=99;        return $result;    }        public function show()    {        echo $this->a;        echo $this->b;    }}$test = new yunke;$test->show();$test2=$test->merge();$test2->show();

输出:

55668899

0 0
原创粉丝点击