Adam Posted October 23, 2008 Share Posted October 23, 2008 Confsuing stuff! Basically say a function name is passed within the URL, for example: "demoFunction" .. this is then collected from within the class construct method and used to try and call a function, using the php functions "is_callable" and "call_user_func" .. however as it points to another method within a class, how would I go about doing that? I've tried the following: if (is_callable($func)) { call_user_func($func); } else { die('Unable to call function: ' .$func); } if (is_callable($this->$func)) { call_user_func($this->$func); } else { die('Unable to call function: ' .$func); } if (is_callable($this->func)) { call_user_func($this->func); } else { die('Unable to call function: ' .$func); } if (is_callable('$this->'.$func)) { call_user_func('$this->'.$func); } else { die('Unable to call function: ' .$func); } Didn't expect much from the last one! .. The $func var is set within the __construct method so there's no need to have $this->func to call the value of $func .. Hopefully that makes sense, and someone knows the soloution?? Cheers for any help! Adam Quote Link to comment https://forums.phpfreaks.com/topic/129745-solved-calling-a-function-based-on-a-var-from-within-a-class-method/ Share on other sites More sharing options...
Adam Posted October 23, 2008 Author Share Posted October 23, 2008 sorted it boys! if (is_callable($this->$func())) { call_user_func($this->$func()); } else { die('Unable to call function: ' .$func); } Quote Link to comment https://forums.phpfreaks.com/topic/129745-solved-calling-a-function-based-on-a-var-from-within-a-class-method/#findComment-672668 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.