ghostcoder Posted June 19, 2009 Share Posted June 19, 2009 Hello. I'm trying to write a little function that checks for the existance of a function AND checks that it is returning true or false. Example follows: function returnMyText($name, $id){ return "My name is $name and my id is $id."; } function func_check($func, $arg){ //somehow I need to convert $arg (which is a number representing the number of arguments the function requires) into multple variables that I can dump into the $func() call below; return echo (function_exists($func) && $func()); } echo func_check('returnMyText', 2); Should run without errors and return True or False. I tried creating a string using a loop, but I didn't figure that would work. So, how can I create any number of dummy variables based on a number and pass them to a function, comma separated? I imagine this isn't too hard, but I don't know how to do it. Anyone care to chime in? Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 19, 2009 Share Posted June 19, 2009 Hello. I'm trying to write a little function that checks for the existance of a function AND checks that it is returning true or false. Example follows: function returnMyText($name, $id){ return "My name is $name and my id is $id."; } function func_check($func, $arg){ //somehow I need to convert $arg (which is a number representing the number of arguments the function requires) into multple variables that I can dump into the $func() call below; return echo (function_exists($func) && $func()); } echo func_check('returnMyText', 2); Should run without errors and return True or False. I tried creating a string using a loop, but I didn't figure that would work. So, how can I create any number of dummy variables based on a number and pass them to a function, comma separated? I imagine this isn't too hard, but I don't know how to do it. Anyone care to chime in? not 100% sure on what you are wanting, lol I'm sleepy and probably shouldn't be reading stuff this code will retun a list of variables seperated by commas <? $varname = '$TestName'; $arg = 2; function RandomVars($varname, $arg) { for($i = 0; $i<= $arg, $i++) { $string = $string.$varname.$i.", "; } return $string; } ?> of course these variables won't have any values and that will just caus your functions to break. could try <? $varname = '$TestName'; $arg = 2; function RandomVars($varname, $arg) { for($i = 0; $i<= $arg, $i++) { $string = $string.$varname.$i."=".$i.","; } return $string; } ?> but wouldn't work in many functions as $varname will always be an int. Quote Link to comment Share on other sites More sharing options...
ghostcoder Posted June 20, 2009 Author Share Posted June 20, 2009 Well, I already tried creating a string, with values separated by commas, and that doesn't work. Your functions return a single variable, and that will break a function that requires multiple variables. if there are three arguments, then the function should create something like return (function_exists($func) && $func($var1, $var2, $var3)); where $var1, etc are generated based on the func_check function $arg variable. The $var should be strings in this case. The dummy variables can be filler text. Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted June 20, 2009 Share Posted June 20, 2009 Well, I already tried creating a string, with values separated by commas, and that doesn't work. Your functions return a single variable, and that will break a function that requires multiple variables. if there are three arguments, then the function should create something like return (function_exists($func) && $func($var1, $var2, $var3)); where $var1, etc are generated based on the func_check function $arg variable. The $var should be strings in this case. The dummy variables can be filler text. ahh I see, I don;t think you can do what yuo require can't think of anything ff top of my head will mull it over gonna watch this topic just incase someone else has an idea I'm intruged Quote Link to comment 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.