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] Link to comment https://forums.phpfreaks.com/topic/7718-using-a-variable-in-a-function-call/ 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] Link to comment https://forums.phpfreaks.com/topic/7718-using-a-variable-in-a-function-call/#findComment-28300 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.