I'm trying to check whether a function exists or not but I keep getting false in my if
I try to call the function like this, where $function is the function name:
if (function_exists($this->module->$function))
{
$this->module->$function($vars);
}
else
{
echo 'no';
}
The variable module is defined as the class where the function should be called:
$this->module = $module;
$this->module = new $this -> module;
Am I missing something here? Thank you!
Just could figure it out: Using method_exists() solved my problem
method_exists($this->module,$function)
I answered this question on my own for people who may have the same problem!
You need to use method_exists():
if (method_exists($this->module, $function)) {
// do stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With