文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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'));
?>
相关阅读 更多 +
排行榜 更多 +
建筑模拟器最新版

建筑模拟器最新版

模拟经营 下载
素人改造师最新版

素人改造师最新版

模拟经营 下载
外星战士幸存者手机版

外星战士幸存者手机版

飞行射击 下载