protected function decode_response($response) {
        // XMLRPC server in Moodle encodes response using function xmlrpc_encode_request() with method==null
        // see {@link webservice_xmlrpc_server::prepare_response()} . We should use xmlrpc_decode_request() for decoding too.
        $method = null;
        $encoding = null;
        if (preg_match('/^<\?xml version="1.0" encoding="([^"]*)"\?>/', $response, $matches)) {
            // Sometimes xmlrpc_decode_request() fails to recognise encoding, let's help it.
            $encoding = $matches[1];
        }
        $r = xmlrpc_decode_request($response, $method, $encoding);
        return $r;
    }