I have the following block of code:
public function __construct($username, $password, $host, $port, $dbname)
{
$SP = new RegistrationProceduresModel($username, $password, $host, $port, $dbname);
// Sanitize all the incoming data
$sanitized = array_map(array($this, 'sanitize'), $_POST);
if(method_exists($SP, $SP->$sanitized['function']()))
{
$SP->$this->$sanitized['function']();
}
else
{
try
{
$val = isset($sanitized['function']) ? $sanitized['function'] . " does not exist in model." : "was not specified";
die("Function " . $val);
}
catch(exception $ex)
{
die("Threw an error after failing to evaluate whether a $_POST method exists. Review controller. " . $ex->getMessage());
}
}
}
public function sanitize($input)
{
return htmlspecialchars(trim($input));
}
The intent of which is to take some post data, check if a method exists within a class, and if so, execute it.
Unfortunately, when I run this I'm receiving the following error and I'm unsure why:
Function getFormList does not exist in model.
I've checked the model and my function definitely exists, and is public - what else could be causing me to reach this point?
method_exists($SP, $SP->$sanitized['function']);
to
method_exists($SP, $sanitized['function']);