Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将对象实例传递到类构造函数时出错_Php_Oop_Guzzle_Psr 7 - Fatal编程技术网

Php 将对象实例传递到类构造函数时出错

Php 将对象实例传递到类构造函数时出错,php,oop,guzzle,psr-7,Php,Oop,Guzzle,Psr 7,我在将PSR-7消息响应(由Guzzle生成)传递到类构造函数时遇到问题 该消息由以下程序生成: $client = new \GuzzleHttp\Client(); $res = $client->request('GET', 'http://pagecrawler/cache.html'); 和我的类构造函数: Class Test { protected $response; public function __construct($response, $db

我在将PSR-7消息响应(由Guzzle生成)传递到类构造函数时遇到问题

该消息由以下程序生成:

$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'http://pagecrawler/cache.html');
和我的类构造函数:

Class Test {

    protected $response;

    public function __construct($response, $db = null)
    {
        $this->$response = $response; /* Line 18 */
    }
}
我得到的错误是:

PHP Catchable fatal error:  Object of class GuzzleHttp\Psr7\Response could not be converted to string

我假设,由于我没有为
$this->response
设置类型,它会毫无问题地分配变量。

这只是一个输入错误。使用
$this->$response
可以将响应对象强制转换为字符串。相反,你应该做
$this->response

这只是一个打字错误。使用
$this->$response
可以将响应对象强制转换为字符串。相反,您应该执行
$this->response

您看到了吗?$this->response,而不是$this->$response@Federico谢谢,就这样!愚蠢的错误-我的所有其他变量设置(
$this->db=$db
等)都是正确的。是否愿意将其添加为我可以接受的答案?您看到了吗?$this->response,而不是$this->$response@Federico谢谢,就这样!愚蠢的错误-我的所有其他变量设置(
$this->db=$db
等)都是正确的。要不要加上它作为答案,这样我就可以接受了?