0

我尝试了很多但没有结果:-

创建表单响应函数:

public static $codes= array('error1','error2','error3');

public static function createFromResponse($response)
{        
    $code = $response->body->category_code; //it contains the values from $codes array

    if (isset(self::$codes[$code])){
        $cn = self::$codes[$code];
    }
    else{
        $cn = get_class();
    }
    return new $cn($response);
}

当前 $cn 包含类 Bookmyroom 并且 $response 是包含错误的对象

例如课堂书房-

class Bookmyroom extends Error
{
   // contains some functions
}

错误类别:-

class Error extends Base
{
    public $response;

    public function __construct($response)
    {
        $this->_objectify($response->body);
    }

    public function _objectify($fields)
    {
        foreach ($fields as $key => $val) {
            $this->$key = $val;
        }
    }
}

只有线

return new $cn($response); 

在第一个函数中

function CreateFormResponse(); 

抛出 500 内部服务器错误 - Bookmyroom

提前谢谢...

4

0 回答 0