文章详情

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


相关阅读 更多 +
排行榜 更多 +
木筏丧尸MOD菜单中文版

木筏丧尸MOD菜单中文版

休闲益智 下载
木筏丧尸免广告版

木筏丧尸免广告版

休闲益智 下载
天空决斗内置MOD菜单最新版本

天空决斗内置MOD菜单最新版本

飞行射击 下载