Issues

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

Issue Type: Bug Created: 2007-09-14T16:08:28.000+0000 Last Updated: 2009-01-11T04:12:03.000+0000 Status: Resolved Fix version(s): - 1.5.3 (28/Jul/08)

Reporter: Enrique Chavez (tmeister) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Rest_Server

Related issues: - ZF-3338

Attachments:

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:

<pre class="highlight">
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:

<pre class="highlight">
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

<pre class="highlight">
<?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

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

Comments

Posted by Darby Felton (darby) on 2007-09-18T13:12:31.000+0000

Assigning to [~davey] to initiate issue review

Posted by Matthew Weier O'Phinney (matthew) on 2007-09-20T12:43:40.000+0000

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.

Posted by Darby Felton (darby) on 2007-09-20T14:00:27.000+0000

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

Posted by Eric Coleman (eric) on 2007-10-31T11:21:59.000+0000

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:

<pre class="highlight">
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;
                         }
                     }
 

Posted by Matthew Weier O'Phinney (matthew) on 2008-05-09T11:59:06.000+0000

Scheduling for next mini release.

Posted by Matthew Weier O'Phinney (matthew) on 2008-07-24T04:21:16.000+0000

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.

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