异步http请教

q13113671764

文档里面说: 所有的异步编码必须在onXXX回调中编写
我想请教下能不能这样写,谢谢!

$http->get('',function ($response){
//这里处理的代码实际是写到其它地方去了
test($response);

});

1761 2 0
2个回答

q13113671764

我想了一下,如果上面方案不行的话,造成的原因应该是作用域的问题,那么下面这个会不会靠谱一些
有必要说明一下,这里代码都是在 onXXX里面,只是解析的代码写到其它地方去了,实在是对异步的实现不理解,知道的回一下,谢谢了.
$responseClass = new ResponseClass();
$http->get('',function ($response)use($responseClass){
//这里处理的代码实际是写到其它地方去了
$responseClass->parse($response);
});

  • 暂无评论
walkor

这里代码都是在 onXXX里面,只是解析的代码写到其它地方去了

可以

年代过于久远,无法发表回答
🔝