Jump to content

[SOLVED] Calling a function based on a var from within a class method?


Adam

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.