What does 'this followed by square brackets' mean in PHP? -


i found 1 code block in laravel below:

/**  * register "before" application filter.  *  * @param  \closure|string  $callback  * @return void  */ public function before($callback) {     return $this['router']->before($callback); } 

what $this['router'] mean @ here? can explain $this['xx'] form? array?

the fact variable called $this means can't ordinary array - variable name reserved current instance of class.

using square brackets access object sign class implements arrayaccess interface - is, can accessed using operators reserved basic arrays.

retrieving value class implements arrayaccess using square bracket notation invokes class's offsetget method, provided key $offset argument. common use allow access class's member variables, class can choose perform action in method.

in case, think you're looking @ laravel application class, result in router item being returned dependency injection container.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -