Page 1 of 1

About function

Posted: Sun Jan 14, 2007 11:32 pm
by classic037
Hi,

any one tell how many parameter we pass in php userdefine function.

Posted: Mon Jan 15, 2007 1:23 am
by Christopher
Search for userdefined() in PHP manual

I don't know of a "userdefine" function in PHP. Are you sure that is what it is called?

Posted: Mon Jan 15, 2007 1:33 am
by classic037
hi,

user define function means function which is created by user..

i m taking about...

Code: Select all

function  <name>([$var1 [= constant]], 
                 [$var2 [= constant]], ...) {
}
now how many parameter (like in code.. $var1,$var2,......) we pass in function..

Posted: Mon Jan 15, 2007 1:37 am
by feyd
Are you asking "how many arguments can we pass to a function"?

The answer to that is as many as your memory or particular install will allow. The actual limit will vary from server to server.

Posted: Mon Jan 15, 2007 2:35 am
by onion2k
I think he's asking for a function that returns the number of expected arguments. For example:

Code: Select all

function userDefinedFunction($var1, $var2, $var3) {
   //Blah blah blah
}
He wants a function returns 3, because it's expecting 3 arguments.

As far as I know it's not possible.

Re: About function

Posted: Mon Jan 15, 2007 7:02 am
by dibyendrah
classic037 wrote:Hi,

any one tell how many parameter we pass in php userdefine function.
As many parameters you have defined in your function. :wink:

Suppose, you have

Code: Select all

function x($a, $b, $c=NULL){
    
}
Here $c is optional and $a & $b is complulsory.

Posted: Mon Jan 15, 2007 8:39 am
by Kieran Huggins
The actual answer is: an unlimited amount.

Use func_get_args() inside your function to return an array of arguments passed to it.

Posted: Mon Jan 15, 2007 9:54 am
by feyd
onion2k wrote:I think he's asking for a function that returns the number of expected arguments. For example:

Code: Select all

function userDefinedFunction($var1, $var2, $var3) {
   //Blah blah blah
}
He wants a function returns 3, because it's expecting 3 arguments.

As far as I know it's not possible.
If this is the case, reflection can do it.

http://php.net/language.oop5.reflection ... onfunction

Note ReflectionFunction::getNumberOfRequiredParameters()