Issues

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

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);
        }

Comments

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

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.