Zend Framework

Zend_Amf_Server::addFunction() throws exception when passed callback of object instance method

Details

Description

Zend_Amf_Server of ZF version 1.7.2 throws an exception when the addFunction() method is called with a callback containing an object instance method as in the following:

$server = new Zend_Amf_Server();
$server->addFunction(array($object, 'somePublicAMFResponderMethod'));

The exception message is simply "Unable to attach function".

It's clear within the addFunction() body why this occurs (for the first array element of $function, $func is an object, not a string or function):

$function = (array) $function;
        foreach ($function as $func) {
            if (!is_string($func) || !function_exists($func)) {
                require_once 'Zend/Amf/Server/Exception.php';
                throw new Zend_Amf_Server_Exception('Unable to attach function');
            }
            $this->_methods[] = Zend_Server_Reflection::reflectFunction($func, $argv, $namespace);
        }

Activity

Hide
Satoru Yoshida added a comment -

Hi, Darby.

Do you mean each message should be different one?
For example,
the parameter is not string nor array,
the parameter is not function name... etc

Show
Satoru Yoshida added a comment - Hi, Darby. Do you mean each message should be different one? For example, the parameter is not string nor array, the parameter is not function name... etc
Hide
Darby Felton added a comment -

No, I wasn't meaning that the exception message should be different based on the type of callback sent. The problem to which I refer in the description is that the addFunction() method claims to be able to accept a valid callback, but an essential callback form is not supported by the current code base. If a user supplies a valid callback using an object instance's method (e.g., array($object, 'somePublicMethod')), then Zend_Amf_Server throws an exception, because $object will pass neither the is_string() test nor the function_exists() test in the addFunction() body.

Show
Darby Felton added a comment - No, I wasn't meaning that the exception message should be different based on the type of callback sent. The problem to which I refer in the description is that the addFunction() method claims to be able to accept a valid callback, but an essential callback form is not supported by the current code base. If a user supplies a valid callback using an object instance's method (e.g., array($object, 'somePublicMethod')), then Zend_Amf_Server throws an exception, because $object will pass neither the is_string() test nor the function_exists() test in the addFunction() body.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: