>  기사  >  백엔드 개발  >  laravel의 $app 애플리케이션 개체는 $app[$k]로 작성되었지만 오류는 보고되지 않습니다! 왜?

laravel의 $app 애플리케이션 개체는 $app[$k]로 작성되었지만 오류는 보고되지 않습니다! 왜?

WBOY
WBOY원래의
2016-12-01 01:27:431216검색

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>

출력

laravel의 $app 애플리케이션 개체는 $app[$k]로 작성되었지만 오류는 보고되지 않습니다! 왜?

하지만 저는 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>

그러면 출력은 다음과 같습니다

laravel의 $app 애플리케이션 개체는 $app[$k]로 작성되었지만 오류는 보고되지 않습니다! 왜?

간단히 말하면 $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>

출력

laravel의 $app 애플리케이션 개체는 $app[$k]로 작성되었지만 오류는 보고되지 않습니다! 왜?

하지만 저는 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>

그러면 출력은 다음과 같습니다

laravel의 $app 애플리케이션 개체는 $app[$k]로 작성되었지만 오류는 보고되지 않습니다! 왜?

간단히 말하면 $app은 분명히 객체인데 $app[$k] 형식으로 어떻게 쓸 수 있나요?

앱은 IlluminateContainerContainer을 상속하고 컨테이너는 ArrayAccess(http://php.net/manual/zh/clas...) 인터페이스를 구현합니다. ArrayAccess 인터페이스는 배열 액세스와 같이 객체에 액세스하는 기능을 제공합니다. 인터페이스의 몇 가지 메소드를 구현하는 한 isset, unset, []를 호출하여 값에 액세스할 수 있습니다.

$this->app['config']도 객체입니다. IlluminateConfigRepository ArrayAccess도 구현하므로 배열로도 사용할 수 있습니다.

ArrayAccess

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.