ghostz00 Posted April 18, 2006 Share Posted April 18, 2006 I want to call a function using a variable.example[code]class example{$var=100;$variable=100;}$func="var"; // or variable$ex=new example;//this is where I need help somehow I need to use the $func variable to call the right variable.echo $ex->($func);[/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted April 18, 2006 Share Posted April 18, 2006 Do you mean this[code]class example{ var $var=100; var $variable=120;}$func1="var";$func2="variable";$ex=new example;echo $ex->$func1; // --> 100echo $ex->$func2; // --> 120[/code]or this?[code]class example{ var $var=100; var $variable=120; function f1() {return $this->var;} function f2() {return $this->variable;}}$func1="f1";$func2="f2";$ex=new example;echo $ex->$func1(); // --> 100echo $ex->$func2(); // --> 120[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.