文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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'));
?>
相关阅读 更多 +
排行榜 更多 +
西安交大通

西安交大通

生活实用 下载
长江云通

长江云通

生活实用 下载
translatez

translatez

生活实用 下载