dpd20130 2013-12-19 06:07
浏览 8
已采纳

未能评估某个方法是否存在于类中并且不确定原因

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?

  • 写回答

1条回答 默认 最新

  • dongyanzhui0524 2013-12-19 06:36
    关注
    method_exists($SP, $SP->$sanitized['function']);
    

    to

    method_exists($SP, $sanitized['function']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?