About function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
classic037
Forum Newbie
Posts: 4
Joined: Sun Jan 14, 2007 11:23 pm
Location: Mumbai
Contact:

About function

Post by classic037 »

Hi,

any one tell how many parameter we pass in php userdefine function.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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?
(#10850)
classic037
Forum Newbie
Posts: 4
Joined: Sun Jan 14, 2007 11:23 pm
Location: Mumbai
Contact:

Post 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..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Re: About function

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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()
Post Reply