在laravel 5.1里的
illuminatefilesystemfilesystemmanager 类中的
getconfig方法中
竟然用
<code class="php">$this->app['config']["filesystems.disks.{$name}"]);</code>返回数组。
但是
<code class="php">$this->app</code>
明明是个对象啊。
对象能用数组的键值取值吗? 这在语法上明明是错的但是神奇的事情还是发生了
这是getConfig方法
<code class="php"> /**
* Get the filesystem connection configuration.
*
* @param string $name
* @return array
*/
protected function getConfig($name)
{
return $this->app['config']["filesystems.disks.{$name}"];
}</code>我单独dd($this->app);
即如下
<code class="php"> /**
* Get the filesystem connection configuration.
*
* @param string $name
* @return array
*/
protected function getConfig($name)
{
dd($this->app);
return $this->app['config']["filesystems.disks.{$name}"];
}</code>输出
但是我dd($this->app'config');即
<code class="php"> protected function getConfig($name)
{
dd($this->app['config']["filesystems.disks.{$name}"]);
return $this->app['config']["filesystems.disks.{$name}"];
}</code>那么输出如下
总之 $app 明明是个对象,怎么能写成 $app[$k] 这样的形式呢?
在laravel 5.1里的
illuminatefilesystemfilesystemmanager 类中的
getconfig方法中
竟然用
<code class="php">$this->app['config']["filesystems.disks.{$name}"]);</code>返回数组。
但是
<code class="php">$this->app</code>
明明是个对象啊。
对象能用数组的键值取值吗? 这在语法上明明是错的但是神奇的事情还是发生了
这是getConfig方法
<code class="php"> /**
* Get the filesystem connection configuration.
*
* @param string $name
* @return array
*/
protected function getConfig($name)
{
return $this->app['config']["filesystems.disks.{$name}"];
}</code>我单独dd($this->app);
即如下
<code class="php"> /**
* Get the filesystem connection configuration.
*
* @param string $name
* @return array
*/
protected function getConfig($name)
{
dd($this->app);
return $this->app['config']["filesystems.disks.{$name}"];
}</code>输出
但是我dd($this->app'config');即
<code class="php"> protected function getConfig($name)
{
dd($this->app['config']["filesystems.disks.{$name}"]);
return $this->app['config']["filesystems.disks.{$name}"];
}</code>那么输出如下
总之 $app 明明是个对象,怎么能写成 $app[$k] 这样的形式呢?
app继承自 IlluminateContainerContainer, 而 Container 实现了ArrayAccess(http://php.net/manual/zh/clas...)接口。ArrayAccess接口提供了像访问数组一样访问对象的能力,只要实现接口的几个方法就可以调用 isset, unset, []方式存取值。
$this->app['config'] 也是个对象 IlluminateConfigRepository 它也实现了 ArrayAccess ,所以也能当数组用。
ArrayAccess
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号