Call a function from string variable in PERL, PHP and C#

PERL

my $function_name = "hello";
&$function_name(10);
function hello() {
my $param = shift;
print "hello $paramn";
}

PHP

$function_name = "hello";
$function_name();
function hello($param) {
echo "hello $paramn";
}

C#

class Program
{
static void Main(string[] args)
{
Type type = typeof(MyReflectionClass);
MethodInfo method = type.GetMethod("Hello");
MyReflectionClass c = new MyReflectionClass();
method.Invoke(c, null);
}
}

public class MyReflectionClass
{
public void Hello(int num)
{
Console.WriteLine("hello {0}", num.ToString());
}
}

Spread the word. Share this post!

Leave A Reply

Your email address will not be published. Required fields are marked *