首页 > PHP有段写法不懂意思,求指教

PHP有段写法不懂意思,求指教

今天看laravel框架代码一个类中有一段代码

public function isLocal()
{
    return $this['env'] == 'local';
}

从来没见过这样的写法$this['env']这样有什么作用?


这是PHP类集合的实现 具体看demo http://blog.sina.com.cn/s/blog_7550abf30101ajda.html


是不是有一个名为__get的方法譬如:

public function __get($key) {
    return $this->var[$key];
}

Application类继承了Container 类 Container类实现了ArrayAccess,
所以Container的实例是支持数组式访问的: $object['key'];
数组式访问在Container里的实现:https://github.com/laravel/framework/blob/4.2/src/Illuminate/Container/Container.php#L814行到末尾
PHP的数组式访问接口:http://php.net/manual/zh/class.arrayaccess.php

@安正超 为你解答 => http://wenda.golaravel.com/question/5

【热门文章】
【热门文章】