mkb5150 Posted February 8, 2010 Share Posted February 8, 2010 Greetings, I am teaching myself and am still a beginner. I am writing a web service which can be called by cURL or a Zend Rest Client. The problem I'm having is that the function takes in several arguments, but some are optional. I set default values for the optional ones, and this works great with cURL, but when I call the function from the Zend client, It tells me I have not supplied enough arguments. Why does it not use the default values? Here is my function definition: public function functionName($a, $b, $c, $d=null, $e=null, $f=null, $g=null) { //... } When I call from cURL as: http://localhost/program/?method=functionName&a=1&b=2&c=3&d=4 it works great. But when I call from Zend as: $va->functionName($a, $b, $c, $d); I get the error: Invalid Method Call to functionName. Requires 7, 4 given. Why does it not use the default values? Also, is there a way to make it so the order of the variables doesn't matter, but instead checks the NAME? with cURL, method=functionName&a=1&b=2 works the same as method=functionName&b=2&a=1 because the arguments match the name of the arguments in the function definition. When using Zend, I would like functionName($a, $b) to work the same as functionName($b, $a) so that values get passed based on variable name, not order. That way if the user wants to provide $a, $b, and $d, they can do so without passing an empty value for $c in the middle. Link to comment https://forums.phpfreaks.com/topic/191413-invalid-method-call-to-functionname-requires-7-4-given/ Share on other sites More sharing options...
teamatomic Posted February 8, 2010 Share Posted February 8, 2010 I would put them into an associative array and pass the array to the function then use extract within the function. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/191413-invalid-method-call-to-functionname-requires-7-4-given/#findComment-1009105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.