相关疑难解决方法(0)

构造函数返回值?

看下面的代码,我看到构造函数正在返回一个值.我认为构造函数只返回对象.有人能告诉我我错过了什么吗?

public function __construct($username = null, $password = null){
        $urlLogin = "{$this->apiHost}/login/$username";

        $postData = sprintf("api_type=json&user=%s&passwd=%s",
                            $username,
                            $password);
        $response = $this->runCurl($urlLogin, $postData);

        if (count($response->json->errors) > 0){
            return "login error";    
        } else {
            $this->modHash = $response->json->data->modhash;   
            $this->session = $response->json->data->cookie;
            return $this->modHash;
        }
    }
Run Code Online (Sandbox Code Playgroud)

php constructor return

25
推荐指数
3
解决办法
3万
查看次数

标签 统计

constructor ×1

php ×1

return ×1