jsonrpc icon indicating copy to clipboard operation
jsonrpc copied to clipboard

Optionals parameters shifted if missing in request

Open vtexier opened this issue 10 years ago • 1 comments

Parameters are ordered by name, but optional parameters not present in request are not handled and the parameters are shifted.

With the function :

updateUser($password = null, $email = null, $receiveEmail = null)

request :

"params":{"receiveEmail":false, "email":"[email protected]"}

bad call :

updateUser("[email protected]", false)

The server ordered well the parameters, but miss the first optional one and call the function with the list receive.

Anyway, thanks for this great bundle, Vincent.

vtexier avatar Aug 08 '14 12:08 vtexier

I've solved the problem by modifying function checkMethod in Server.php.

foreach ($refParams as $arg)
        {

          $argName = $arg->getName();

          if (array_key_exists($argName, $named))
          {
            $params[] = $named[$argName];
            unset($named[$argName]);
          }
          else
          {
            if (!$arg->isOptional())
            {
                $res = false;
                break;
            } else {
                $params[] = $arg->getDefaultValue();
            }
          }

        }

Hope it helps!

vtexier avatar Aug 08 '14 13:08 vtexier