suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Laravel – Wie rufe ich nicht-statische Methoden in PHP statisch auf?

Statischer Aufruf im Larave-Projekt

Fassade

Die Titelmethode in der Admin-Klasse ist nicht statisch

Wie wird das erreicht?

黄舟黄舟2768 Tage vor1060

Antworte allen(1)Ich werde antworten

  • 学习ing

    学习ing2017-07-05 10:04:01

    归根结底是通过 魔术方法 __callStatic 实现的

    Illuminate\Support\Facades\Facade 代码最下方

    https://github.com/illuminate...

     /**
         * Handle dynamic, static calls to the object.
         *
         * @param  string  $method
         * @param  array   $args
         * @return mixed
         *
         * @throws \RuntimeException
         */
        public static function __callStatic($method, $args)
        {
            $instance = static::getFacadeRoot();
            if (! $instance) {
                throw new RuntimeException('A facade root has not been set.');
            }
            return $instance->$method(...$args);
        }

    关于 FacadeLavavel 比较重要的特性之一,可以详细了解下它的实现。

    Antwort
    0
  • StornierenAntwort