Laravel Application Object $app, written $app[$k] unexpectedly not error! Why?

Source: Internet
Author: User

In the laravel 5.1 .
In the Illuminatefilesystemfilesystemmanager class
In the getconfig method
actually use

$this->app['config']["filesystems.disks.{$name}"]);

Returns an array.

But

$this->app

It's an object, obviously.
Can objects use the value of an array's key values? It's syntactically wrong, but the magic is still happening.

This is the GetConfig method.

 /**     * Get the filesystem connection configuration.     *     * @param  string  $name     * @return array     */    protected function getConfig($name)    {               return $this->app['config']["filesystems.disks.{$name}"];    }

I am alone DD ($this->app);
is as follows

 /**     * Get the filesystem connection configuration.     *     * @param  string  $name     * @return array     */    protected function getConfig($name)    {        dd($this->app);        return $this->app['config']["filesystems.disks.{$name}"];    }

Output

But I dd ($this->app ' config ');

 protected function getConfig($name)    {        dd($this->app['config']["filesystems.disks.{$name}"]);        return $this->app['config']["filesystems.disks.{$name}"];    }

Then the output is as follows

In short $app is clearly an object, how can write $app [$k] this form?

Reply content:

In the laravel 5.1 .
In the Illuminatefilesystemfilesystemmanager class
In the getconfig method
actually use

$this->app['config']["filesystems.disks.{$name}"]);

Returns an array.

But

$this->app

It's an object, obviously.
Can objects use the value of an array's key values? It's syntactically wrong, but the magic is still happening.

This is the GetConfig method.

 /**     * Get the filesystem connection configuration.     *     * @param  string  $name     * @return array     */    protected function getConfig($name)    {               return $this->app['config']["filesystems.disks.{$name}"];    }

I am alone DD ($this->app);
is as follows

 /**     * Get the filesystem connection configuration.     *     * @param  string  $name     * @return array     */    protected function getConfig($name)    {        dd($this->app);        return $this->app['config']["filesystems.disks.{$name}"];    }

Output

But I dd ($this->app ' config ');

 protected function getConfig($name)    {        dd($this->app['config']["filesystems.disks.{$name}"]);        return $this->app['config']["filesystems.disks.{$name}"];    }

Then the output is as follows

In short $app is clearly an object, how can write $app [$k] this form?

The app inherits from IlluminateContainerContainer , and Container implements it ArrayAccess (Http://php.net/manual/zh/clas ... Interface The Arrayaccess interface provides the ability to access an object like an array, as long as several methods of implementing the interface can invoke Isset, unset, [] to access the value.

$this->app['config']IlluminateConfigRepositoryIt also implements the arrayaccess, so it can also be used as an array.

ArrayAccess

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.