search

Home  >  Q&A  >  body text

Laravel - How to statically call non-static methods in PHP?

Static call in larave project

facade

The title method in the Admin class is non-static

How is this achieved?

黄舟黄舟2701 days ago1010

reply all(1)I'll reply

  • 学习ing

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

    In the final analysis, it is achieved through the magic method __callStatic

    IlluminateSupportFacadesFacade Code at the bottom

    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);
        }

    About Facade is one of the more important features of Lavavel. You can learn more about its implementation.

    reply
    0
  • Cancelreply