Issues

ZF-9374: Zend_Rest_Server does not properly handle optional parameters when anonymous (arg1, etc) parameters are passed in

Issue Type: Bug Created: 2010-03-08T17:49:13.000+0000 Last Updated: 2012-11-20T21:38:00.000+0000 Status: Open Fix version(s): Reporter: Jonathan Csanyi (jcsanyi) Assignee: None Tags: - Zend_Rest_Server

Related issues: - ZF-9373

Attachments: - trunk-correct.diff

Description

When anonymous parameters are passed in, and one or more optional parameters are missing, the default values are not correctly filled in, and the call fails with a 'missing arguments' error message.

Comments

Posted by Jonathan Csanyi (jcsanyi) on 2010-03-08T17:51:19.000+0000

There was already a unit test for this functionality, but the expected value was incorrectly hard-coded backwards, so the failure was counting as a pass.

Posted by Jonathan Csanyi (jcsanyi) on 2010-03-08T17:53:36.000+0000

Attached patch fixes Zend_Rest_Server, and accompanying unit tests.

Posted by Jonathan Csanyi (jcsanyi) on 2010-03-08T18:00:28.000+0000

'sorry.. original diff had a misleading/incorrect comment. This is the correct diff.

Posted by Claude Duvergier (cduv) on 2010-07-15T03:23:47.000+0000

I agree with Jonathan Csanyi.

I ran into that problem an thought Zend_Rest_Client was the cause as it uses the "arg1" query parameter name when only one argument is passed to the server (see ZF-4910). But is seems that Zend_Rest_Server is guilty.

With the following server PHP code:

<pre class="highlight">
class MyServerImpl
{
  public function myMethod ($var)
  {
    $return $var*$var;
  }
  public function myOtherMethod ($var = 3)
  {
    $return $var*$var;
  }
}
$server = new Zend_Rest_Server();
$server->setClass('MyServerImpl');
$server->handle();

The following client PHP code:

<pre class="highlight">
$client
  ->myMethod(5)
  ->get();

Issues the following request: server.php?method=myMethod&myMethod=5&arg1=5

Which is handled by Zend_Rest_Server::handle() as

<pre class="highlight">
$missing_args[0] = 'var';
$calling_args[1] = 5
=> myMethod(5);

{color:green}Which is correct.{color}

And the other following client PHP code:

<pre class="highlight">
$client
  ->myOtherMethod(5)
  ->get();

Issues the following request: server.php?method=myOtherMethod&myOtherMethod=5&arg1=5

Which is handled by Zend_Rest_Server::handle() as

<pre class="highlight">
$missing_args[] = array();
$calling_args[0] = 3;
$calling_args[1] = 5;
=> myOtherMethod(3);

{color:red}Which is incorrect.{color}

The solution would be to either use 0-based array everywhere, or the given "library/Zend/Rest/Server.php" DIFF file [^trunk-correct.diff].

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts