Issues

ZF-1949: A blank page appears if there's any missing method's argument.

Description

A blank page appears if there's any missing method's argument when calling from a url (sent as HTTP GET variables)

This issue appears when application reaches this line:


throw new Zend_Rest_Server_Exception('Invalid Method Call to ' . $this->_method . '. Requires ' . count($func_args) . ', ' . count($calling_args) . ' given.', 400);

If I replace that line with:


throw new Exception("Fails in line 149");

A blank page appears again, but if I error message is echoed everything works just fine.

File Zend/REST/Server.php line 149

I thought it was caused because of a php fatal error, but I don't find that yet.

I've had this issue in two different hosts:

Solaris 10 Apache 2 PHP 5.2.1

CentOS Apache 2 PHP 5.2.1

Here's my testing code:

service PHP


<?php
        ini_set('error_reporting', E_ALL);
        require_once 'Zend/Rest/Server.php';
        require_once 'test.php';
        $server = new Zend_Rest_Server();
        $server->setClass('test');
        $server->handle();
?>

Test.php


<?php
class test
{
        /**
        * Test Method
        *
        * @param string $to
        * @param string $say
        * @return bool
        */
        public function sayHi($to, $say)
        {
                return "Good $say, $to";
        }
}
?>

Comments

Assigning to [~davey] to initiate issue review

This is a simple case of an uncaught exception, that, because you must have display_errors off, results in no return content. The question is whether Zend_Rest_Server should do more exception handling and have a standard type of error response when exceptions are detected; I will discuss this with Davey.

Reducing priority to minor, since using a {{try...catch()}} block appears to be an easy workaround.

This issue occurs -even- if a method has default arguments...

Change davey's example to test class to public function sayHi($to = null, $say = null)

Here's a fix:


Index: Zend/Rest/Server.php
===================================================================
--- Zend/Rest/Server.php    (revision 6696)
+++ Zend/Rest/Server.php    (working copy)
@@ -135,13 +135,15 @@
                     foreach ($func_args as $arg) {
                         if (isset($request[strtolower($arg->getName())])) {
                             $calling_args[] = $request[strtolower($arg->getName())];
+                        } else if ($arg->isOptional()) {
+                            $calling_args[strtolower($arg->getName())] = $arg->getDefaultValue();
                         }
                     }
 
                     foreach ($request as $key => $value) {
                         if (substr($key, 0, 3) == 'arg') {
                             $key = str_replace('arg', '', $key);
-                            $calling_args[$key]= $value;
+                            $calling_args[$key] = $value;
                         }
                     }
 

Scheduling for next mini release.

Fixes for both the case of missing required and missing optional arguments have been committed to trunk and 1.5 and 1.6 release branches.