Jump to content

creating dummy variables in a function-check function?


ghostcoder

Recommended Posts

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?

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.

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.

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

Archived

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

×
×
  • 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.