Is it possible to curry method calls in PHP?

前端 未结 8 2439
日久生厌
日久生厌 2020-12-06 01:17

I have a SoapClient instance generated for a WSDL file. All except one of the method invocations require the username and the password to be passed id.

Is there any

相关标签:
8条回答
  • 2020-12-06 02:06

    Although not a very good solution, you could write a basic wrapper class that used PHPs magic methods (Specifically __call) to call the actual function but append the user name and password to the argument list.

    Basic example:

    class SC
    {
        private $user;
        private $pass;
    
        public function __construct($user, $pass)
        {
            $this->user = $user;
            $this->pass = $pass;
        }
    
        public function __call($name, $arguments) 
        {
            $arguments = array_merge(array($this->user, $this->pass), $arguments);  
            call_user_func_array($name, $arguments);
        }
    }
    
    0 讨论(0)
  • 2020-12-06 02:08

    You can use partial application and curry functions from Non-standard PHP library.

    0 讨论(0)
提交回复
热议问题