wordpress-xmlrpc-client icon indicating copy to clipboard operation
wordpress-xmlrpc-client copied to clipboard

Remove limitation on closures

Open dnaber-de opened this issue 10 years ago • 1 comments

The current implementation (in 2.4.0) of WordPressClient::_logError() requires callbacks to be closures or function strings. Thus it is not possible to attach a class method as callback, which would make it easier to separate the callback from a logger.

However, if the callbacks would called instead by call_user_func_array() any callable type would be possible:


    private function _logError()
    {
        $callbacks = $this->_getCallback('error');
        $event = array(
            'event'    => 'error',
            'endpoint' => $this->_endPoint,
            'request'  => $this->_request,
            'proxy'    => $this->_proxyConfig,
            'auth'     => $this->_authConfig,
        );
        foreach($callbacks as $callback)
        {
            call_user_func_array($callback, array($this->_error, $event));
        }
    }

dnaber-de avatar Sep 24 '14 13:09 dnaber-de

@dnaber-de Try using the magic __invoke() method inside a class.

franz-josef-kaiser avatar May 14 '15 10:05 franz-josef-kaiser