How to add methods dynamically

后端 未结 8 1344
故里飘歌
故里飘歌 2021-01-01 15:15

I\'m trying to add methods dynamically from external files. Right now I have __call method in my class so when i call the method I want, __call inc

8条回答
  •  时光说笑
    2021-01-01 15:59

    You can create an attribute in your class : methods=[]
    and use create_function for create lambda function.
    Stock it in the methods attribute, at index of the name of method you want.
    use :

    function __call($method, $arguments)
    {
       if(method_exists($this, $method))
          $this->$method($arguments);
       else
          $this->methods[$method]($arguments);
    }
    

    to find and call good method.

提交回复
热议问题