Triggering __call() in PHP even when method exists

后端 未结 2 991
借酒劲吻你
借酒劲吻你 2020-12-30 02:31

The PHP documentation says the following about the __call() magic method:

__call() is triggered when invoking inaccessible methods in an

2条回答
  •  一个人的身影
    2020-12-30 02:42

    How about just make all your other methods protected, and proxy them through __callStatic?

    namespace test\foo;
    
    class A
    {
        public static function __callStatic($method, $args)
        {
            echo __METHOD__ . "\n";
    
            return call_user_func_array(__CLASS__ . '::' . $method, $args);
        }
    
        protected static function foo()
        {
            echo __METHOD__ . "\n";
        }
    }
    
    A::foo();
    

提交回复
热议问题