在laravel 5.1里的
IlluminateFilesystemFilesystemManager 类中的
getConfig方法中 
竟然用
$this->app['config']["filesystems.disks.{$name}"]);返回数组。
但是
$this->app明明是个对象啊。
对象能用数组的键值取值吗? 这在语法上明明是错的但是神奇的事情还是发生了
这是getConfig方法
 /**
     * Get the filesystem connection configuration.
     *
     * @param  string  $name
     * @return array
     */
    protected function getConfig($name)
    {
       
        return $this->app['config']["filesystems.disks.{$name}"];
    }我单独dd($this->app);
即如下
 /**
     * Get the filesystem connection configuration.
     *
     * @param  string  $name
     * @return array
     */
    protected function getConfig($name)
    {
        dd($this->app);
        return $this->app['config']["filesystems.disks.{$name}"];
    }输出

但是我dd($this->app'config');即
 protected function getConfig($name)
    {
        dd($this->app['config']["filesystems.disks.{$name}"]);
        return $this->app['config']["filesystems.disks.{$name}"];
    }那么输出如下

总之 $app 明明是个对象,怎么能写成 $app[$k] 这样的形式呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
app继承自
IlluminateContainerContainer, 而 Container 实现了ArrayAccess(http://php.net/manual/zh/clas...)接口。ArrayAccess接口提供了像访问数组一样访问对象的能力,只要实现接口的几个方法就可以调用 isset, unset, []方式存取值。$this->app['config']也是个对象IlluminateConfigRepository它也实现了 ArrayAccess ,所以也能当数组用。ArrayAccess