Today look at Laravel framework code there's a piece of code in a class
public function isLocal(){ return $this['env'] == 'local';}
I've never seen anything like it. $this['env']
Reply content:
Today look at Laravel framework code there's a piece of code in a class
public function isLocal(){ return $this['env'] == 'local';}
I've never seen anything like it. $this['env']
The application class inherits the container class container class and implements the Arrayaccess,
So the example of container is to support array-type access: $object [' key '];
Implementation of array-type access in Container: https://github.com/laravel/framework/blob/4.2/src/Illuminate/Container/Container.php#L814 line to the end
PHP array-type access interface: http://php.net/manual/zh/class.arrayaccess.php
@ Ang Sul solution for you = HTTP://WENDA.GOLARAVEL.COM/QUESTION/5
Is there a method called __get , for example:
public function __get($key) { return $this->var[$key];}
This is the implementation of the PHP class collection specifically see demo http://blog.sina.com.cn/s/blog_7550abf30101ajda.html