fbt045 发表于 2012-12-26 11:06

php类中变量的一个疑问

各位高手,现在又这样一个类:
class a{
...
        function __construct($bb, $response) {
                $this->bb= $bb;
                $this->user   = $this->bb->user();
                $this->rootdir= $this->bb->get('webdir');
                $this->tpldir   = $this->rootdir.'/server/appliance/tpl';
                $this->response = $response;
                $this->file   = $this->openqrm->file();
                $this->lang   = $this->user->translate($this->lang, $this->rootdir."/server/appliance/lang", 'appliance.ini');
        }   
...
}
上面的this指针引用user、tpldir等都是类中未定义的变量,我很不理解还能这样用,请大家帮解析一下,谢谢哈

satrun7 发表于 2012-12-26 12:07

要明白php是动态语言, PHP中不强调需要初始化变量。

maochanglu 发表于 2012-12-26 13:12

弱类型的语言,有些概念是不一样的。

linux_c_py_php 发表于 2012-12-26 15:31

脚本语言大多都这样, php, python, 赋值即可, 即便是类成员变量.

fbt045 发表于 2012-12-27 14:30

感谢楼上各位,看来php使用真是很灵活
页: [1]
查看完整版本: php类中变量的一个疑问