PHP is handling incorrectly my static call

前端 未结 5 1079
野趣味
野趣味 2020-12-17 05:34

I\'m havinh a problem on PHP 5.3. I need to call a method by using __callStatic, but if I use it in a instancied object, PHP call __call instead.

5条回答
  •  无人及你
    2020-12-17 06:14

    Good news

    I make a BIG work arround, but it works pretty fine. This is the code:

    class NoContext {
        public static function call($callback, $args = null){
            return call_user_func_array($callback, $args ?: array());
        }
    }
    

    You need to call NoContext::call (statically) like you call call_user_func or similar. It will to remove the $this context. I still thinks that it is a PHP bug, but...

    To solve my problem, I do:

    class B extends A {
        function useCallStatic(){
            NoContext::call('A::foo');
        }
    }
    

    And it will prints: Fine!.

    Thanks everybody that help me. I really learn too much with your replies and I wait that my tips be userful sometime to you.

提交回复
热议问题