Welcome Guest, Not a member yet? Register   Sign In
call_user_func() vs. $func_name()
#1

[eluser]neomech[/eluser]
I'm trying to wrap my head around a small issue I'm having.

I have several functions sitting in my model, and I grab the name of one of them in my code dynamically, which I store as, say, $func_name.

Now I know that call_user_func($func_name, $var) is supposed to be the preferred method over $func_name($var). However, I can't seem to call any model functions from the controller using call_user_func.

This works:
Code:
$this->Sample_model->$func_name($var);

This doesn't:
Code:
//tried this way
$this->Sample_model->call_user_func($func_name,$var);
//also tried this way
call_user_func($this->Sample_model->$func_name, $var);
I suspect I should be able to call a function in the model from my controller using call_user_func, but if so, I'm doing something wrong. Any suggestions?


Messages In This Thread
call_user_func() vs. $func_name() - by El Forum - 10-11-2010, 07:23 PM
call_user_func() vs. $func_name() - by El Forum - 10-11-2010, 08:47 PM
call_user_func() vs. $func_name() - by El Forum - 10-11-2010, 10:06 PM
call_user_func() vs. $func_name() - by El Forum - 10-12-2010, 07:04 AM
call_user_func() vs. $func_name() - by El Forum - 10-12-2010, 02:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB