Jump to content

[SOLVED] Function Name Inside A Variable


Zimi

Recommended Posts

Use $mvar();

 

However why would want to store function names in a variable? Make sure these variables are not set by the user otherwise you could cause security exploits in your code.

Don't know why he need it Oo

Can you please explain me about $mvar()? google and php.net gives me nothing =p

Umm, $myvar is your actual variable, the () is so PHP calls the function

 

eg

$var = 'hello';

function hello() { return 'hello world'; };

echo $var();

 

Hey wow I didn't know you could do that; learn somethin' new every day :) I was just gonna suggest eval()

In a primitive example it doesn't show much use.  the only realistic example is in a need to have a function be executed based off a user's input but even then a switch can be the same or better assuming a reasonable number of choices.

 

 

Why use eval??

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.