文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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();
?>


相关阅读 更多 +
排行榜 更多 +
合合合军团

合合合军团

策略塔防 下载
街头滑板

街头滑板

体育竞技 下载
武者生存

武者生存

体育竞技 下载