(on Tuesday, 31 March 2009, 12:05 PM -0700):
>
> I am working with creating a Zend_Json_Server and setting some classes like
> so:
>
> $server = new Zend_Json_Server();
>
> $server->setClass('MyClass', 'mynamespace');
>
> When I try to get the smd for this, Zend_Reflection throws the following
> error about my class:
>
> Zend_Server_Reflection_Exception Object
> "Variable number of arguments is not supported for services (except optional
> parameters). Number of function arguments must currespond to actual number
> of arguments described in a docblock."
>
> I understand exactly what this means and have gotten this code to work using
> some less complex classes - however, on the class I am attempting to expose
> right now, I just cannot find where I might have a discrepancy in my
> docblock.
>
> It would be extremely usefull if the Zend_Server_Reflection threw an
> exception that could help pinpoint which method it was having problems
> with... Has anyone had a similar experience?
Wow... I'm not sure how that exception message could be any more clear,
actually.
What it's saying is that there is a discrepancy with the number of
arguments defined in the function call and those in its corresponding
docblock. As an example:
/**
* Do something
*
* @param string $foo
* @return string
*/
public function doSomething($foo, $bar)
{
}
In this example, your function requires 2 parameters -- but your
docblock is only reporting one of them. This is an issue as we cannot
infer any type information on the second parameter -- and thus an
exception is raised.
The opposite is also true:
/**
* Do something
*
* @param string $foo
* @return string
*/
public function doSomething()
{
}
In this case, you may be using func_get_args() to process variable
numbers of arguments in your method. Being a good developer, you've
documented the fact that you might accept a parameter. However, because
there is no corresponding _real_ parameter in the method definition,
reflection is unaware of it, leading to a mismatch between the two.
Again, an exception is raised.
Both situtations are summed up nicely in the last sentence of that
exception message:
"Number of function arguments must correspond to actual number of
arguments described in a docblock."
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论