Component::__construct($config); 不明白这段代码为什么能实现? [ 求助交流 ]
今天读源代码的时候发现一段代码实在理解不了。
yii\vendor\yiisoft\yii2\base\Application.php 中__construct 调用 Component::__construct($config) 。而且
Component::__construct 这里的$this居然指向\base\Application。
两个疑问。
1.Component::__construct不是static方法,为什么要这样调用
2.为什么Component::__construct里的$this指向调用的类
public function __construct($config = [])
{
    // 为什么这里的$this等于 yii\base\Application\
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}
共 3 条回复
Lion2015
            注册时间:2015-03-27
最后登录:2015-07-22
在线时长:5小时0分
    最后登录:2015-07-22
在线时长:5小时0分
- 粉丝2
- 金钱130
- 威望0
- 积分180

