1337coder2006 Posted June 26, 2006 Share Posted June 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12925-arbitrary-number-of-arguments/ Share on other sites More sharing options...
.josh Posted June 26, 2006 Share Posted June 26, 2006 polymorphism is the keyword you want to use in your search. Quote Link to comment https://forums.phpfreaks.com/topic/12925-arbitrary-number-of-arguments/#findComment-49610 Share on other sites More sharing options...
1337coder2006 Posted June 26, 2006 Author Share Posted June 26, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/12925-arbitrary-number-of-arguments/#findComment-49617 Share on other sites More sharing options...
trq Posted June 26, 2006 Share Posted June 26, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/12925-arbitrary-number-of-arguments/#findComment-49665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.