Jump to content

Call a function with parameters stored within a variable as a String.


Recommended Posts

Is this possible?

 

For example

 

$variable="functionOne('param1','param2')";

 

Another example

 

$varaible2="functionOne(functionTwo(1))";

 

Is it possible to execute $variable which would then call functionOne and pass it its parameters? And is it possible to execute $variable2 which would call functionOne which would call functionTwo?

Here's another basic example:

 

function f1($var1){
   $what = $var1;
   return $what;
}

function f2($var2){
   $what2 = $var2 + 2;
   return $what2;
}

$variable = f1(f2(1));
echo $variable;

?>

 

As long as f2 returns something it will pass it to f1 which returns $what and variable is assigned to it.

 

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.