Zend Framework

A blank page appears if there's any missing method's argument.

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.5.3
  • Component/s: Zend_Rest_Server
  • Labels:
    None
  • Fix Version Priority:
    Must Have

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";
        }
}
?>

Issue Links

Activity

Hide
Darby Felton added a comment -

Assigning to Davey Shafik to initiate issue review

Show
Darby Felton added a comment - Assigning to Davey Shafik to initiate issue review
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.
Hide
Darby Felton added a comment -

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

Show
Darby Felton added a comment - Reducing priority to minor, since using a try...catch() block appears to be an easy workaround.
Hide
Eric Coleman added a comment -

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;
                         }
                     }
Show
Eric Coleman added a comment - 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;
                         }
                     }
Hide
Matthew Weier O'Phinney added a comment -

Scheduling for next mini release.

Show
Matthew Weier O'Phinney added a comment - Scheduling for next mini release.
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
30m
Original Estimate - 30 minutes
Remaining:
30m
Remaining Estimate - 30 minutes
Logged:
Not Specified
Time Spent - Not Specified