1

How would I call a php function from a variable.

For example:

$variable = functionname;

so when calling $variable this will return functionname();

I have tried the following:

$variablereturn = $variable."(sometext)";
print $variablereturn;

and

print $variable."(".  print $variabletext. ");";

neither seem to work.

4
  • Did you try the obvious? $variable('sometext');"? Commented Jan 15, 2015 at 17:30
  • 1
    php.net/manual/en/functions.variable-functions.php Commented Jan 15, 2015 at 17:30
  • 2
    All you need to do is to read manual. But instead you create another question for SO. Commented Jan 15, 2015 at 17:31
  • Not sure why I didnt think of that. $variable('sometext'); works thanks Niet its been a long day. Commented Jan 15, 2015 at 17:36

1 Answer 1

1

Just use the following:

$variable = 'function_name';
$variable('your_argument');

Documentation

Sign up to request clarification or add additional context in comments.

1 Comment

I had no idea this was possible.. Since when?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.