Jump to content

Archived

This topic is now archived and is closed to further replies.

1337coder2006

Arbitrary Number of Arguments

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.

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.