namespace think\exception;
use think\Response;
class HttpResponseException extends \RuntimeException
{
/**
* @var Response
*/
protected $response;
public function __construct(Response $response)
{
//位置1
$this->response = $response;
}
public function getResponse()
{
//位置2
return $this->response;
}
}
我在__construct函数中是有数据的,但在getResponse函数中 $this->response数据就没有了
这个是什么原因
不太懂你这个php的东西,但是大致的问题我给你说下:你这个赋值过程只是把response的引用赋值给this->response,并没有申请一个新的空间存储,用的还是原来的同一块空间,传进来的response如果用完后销毁的话,你这个得到的response就是空了。你想想办法把这块空间申请一下应该就行了。
把_construct改为_initialize或者initialize