ZF-1865: Declare param in find() function to match docblock @param
Description
cbijlsma writes:
I have a class that extends Zend_Db_Table_Abstract. Just before calling the {{parent::__construct()}} method, I make a call to {{Zend_Server_Reflection::reflectClass(get_class($this))}}.
When I do so, I get
fatal error: Fatal error: Call to a member function isOptional() on a non-object
in /opt/zf/library/Zend/Server/Reflection/Function/Abstract.php on line 348
It appears that this happens when the function {{Zend_Db_Table_Abstract::find()}} is evaluated by the {{_reflect()}} method in the class above. While looking for a solution I found this message on the ZF Issue Tracker, but it doesn't seem to be the exact same case. Further looking on any forum doesn't give me any helpful results, too.
FYI: I'm using the ZF 1.0.1 in combination with PHP 5.2.3-1+b1. Below this the code I think is relevant.
class My_Db_Table extends Zend_Db_Table_Abstract {
public function __construct($config = null){
echo("My_Db_Table::__construct()");
$refClass = Zend_Server_Reflection::reflectClass(get_class($this));
if($config == null){
parent::__construct();
}else{
parent::__construct($config);
}
}
}
Comments
Posted by Bill Karwin (bkarwin) on 2007-08-20T12:21:33.000+0000
Okay, I see what's going on. The declaration of Zend_Db_Table_Abstract::find() is as follows:
It is documented that a function can declare an empty parameter list, but read its parameters with {{func_get_args()}}. See code example at http://php.net/func-get-args
However, Zend_Server_Reflection has some logic that inspects the docblock and assumes that every {{@param}} tag corresponds to a parameter that is declared in the function signature, and therefore represented in the reflection object.
So we must solve this with one of the following solutions:
Declare parameters in function signatures. For functions with variable number of parameters, make sure that at least the {{@param}} tags in the docblock match the declared function parameters.
Remove {{@param}} tags from docblocks of functions with variable arguments.
Change the logic in Zend_Server_Reflection to double-check that the parameter is encoded in the reflection data before trying to dereference it.
I'd prefer solution #1, and it wouldn't hurt to do the double-checking as well (#3).
I grepped through the ZF library for other cases where the docblock documents a {{@param}} but the function prototype doesn't declare any params. There is only one other such case, in {{Zend_View_Helper_DeclareVars::declareVars()}}.
Posted by Bill Karwin (bkarwin) on 2007-08-20T18:28:54.000+0000
Fixed in revision 6162.
Posted by Wil Sinclair (wil) on 2008-01-23T18:28:46.000+0000
Updating Fix Version to follow issue tracker conventions.