文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>向构造方法中传弟对象变量

向构造方法中传弟对象变量

时间:2007-06-15  来源:liuxingyuyuni


实现对对功能的扩展,例如可传如模板,ajax等
?php
    class Person
    {
        public      $name    =    null;
        public     $age     =     0;
        private     $money =    0;
        private $otherObj = null;
        public function __construct($name, $age, $money, $obj)
        {
            $this->name     =     $name;
            $this->age     =      $age;
            $this->money    =     $money;
            $this->otherObj =     $obj;
        }
        public function getObj()
        {
            return $this->otherObj;
        }
    }
    class Test
    {
        public $hi = 'hi';
        public function sayHello()
        {
            echo 'hello!~';
        }
    }
    $test = new Test();
    $per = new Person('小破孩',24, 1000000, $test);
    $per->getObj()->sayHello();
?>


相关阅读 更多 +
排行榜 更多 +
空中跑酷汉化版

空中跑酷汉化版

赛车竞速 下载
修仙传说

修仙传说

角色扮演 下载
魔界零之迷宫

魔界零之迷宫

冒险解谜 下载