Jump to content

Arbitrary Number of Arguments


1337coder2006

Recommended Posts

Hello, nice site.

I am trying to create a class or a function (if its possible) that can have an unknown number of arguments. I've searched google/various forums and i have found nothing, can anyone point me to a good tutorial on this?

I should probably just keep it simple and pass the arguments as an array, but it would be nice to know how to do this.
Link to comment
Share on other sites

[!--quoteo(post=388004:date=Jun 26 2006, 04:21 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 26 2006, 04:21 AM) [snapback]388004[/snapback][/div][div class=\'quotemain\'][!--quotec--]
polymorphism is the keyword you want to use in your search.
[/quote]

i did a search on that but it led me to a tutorial on object overloading, i'll try again, thank you.

Also, I think the solution I'm looking for is just to use func_get_args which will return the function arguments in an array.
Link to comment
Share on other sites

[code]
function test() {
  $argscount = func_num_args();
  $args = func_get_args();
  for ($i = 0;$i < $argscount;$i++) {
    echo "you passed in {$arg[$i]} as argument $i\n";
  }
}
test(2,4,7,"foo",3);
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.