文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一段PHP对象访问类私有方法的代码

一段PHP对象访问类私有方法的代码

时间:2010-11-05  来源:陆西星

<?php
class Test
{
    private $foo;
 
    public function __construct($foo)
    {
        $this->foo = $foo;
    }
    private function bar()
    {
        echo 'Accessed the private method.';
    }
    public function baz(Test $other)
    {
        // We can change the private property:
        $other->foo = 'hello';
        var_dump($other->foo);
        // We can also call the private method:
        $other->bar();
    }
}
$test = new Test('test');
$test->baz(new Test('other'));
?>
相关阅读 更多 +
排行榜 更多 +
广州货源网

广州货源网

购物比价 下载
隐秘的原罪2

隐秘的原罪2

音乐节奏 下载
飞羊精选

飞羊精选

购物比价 下载