[英]Why am I getting “Error: Call to a member function end() on null” using Aerys?
I'm trying to put aerys on top of my cms but getting error. 我试图将aerys放在我的cms上,但出现错误。 As I see the backend returns not null value - #1 in stacktrace but it doesn't reach $resp->end().
如我所见,后端返回的值不为null-stacktrace中的#1,但未达到$ resp-> end()。 I'm stucked trying to get that value to the end().
我一直试图将那个值传递到end()上。
Code example 代码示例
$router = router()
->route("GET", "/exchangews", $websocket)
->route('*', '/{resource}/?', function (Aerys\Request $req, Aerys\Response $res, array $route) {
// copy params and make scalar the single values
$params = [];
foreach(($param = yield $req->getAllParams()) as $key => $val){
if(count($val)==1)$params[$key] = array_pop($val);
}
$headers = $req->getAllHeaders();
$bodyProm = Amp\call( function() use($params, $headers, $route){
try{
$lead = new RequestHandler($headers, array_merge($params, $route));
$body = $lead->proccess();
return $body;
}catch(\Exception $e){
//
}
});
$body = yield $bodyProm;
// run my application
$resp->end($body);
# matched by e.g. /user/rdlowrey/42
# but not by /user/bwoebi/foo (note the regex requiring digits)
# $res->end("The user with name {$route['name']} and id {$route['id']} has been requested!");
});
Stack trace: 堆栈跟踪:
Error: Call to a member function end() on null in /Library/WebServer/Documents/ingine/index_aerys.php:47
Stack trace:
#0 [internal function]: {closure}(Object(Aerys\StandardRequest), Object(Aerys\StandardResponse), Array)
#1 /Library/WebServer/Documents/ingine/vendor/amphp/amp/lib/Coroutine.php(74): Generator->send('<!DOCTYPE html ...')
#2 /Library/WebServer/Documents/ingine/vendor/amphp/amp/lib/Success.php(33): Amp\Coroutine->Amp\{closure}(NULL, Array)
....
What's wrong? 怎么了?
This seems to be a simple typo. 这似乎是一个简单的错字。 You define
Aerys\\Response $res
as parameter, but then use $resp
and try to call a function on it, which is undefined. 您将
Aerys\\Response $res
定义为参数,但是使用$resp
并尝试对其调用未定义的函数。 You should enable error reporting during development. 您应该在开发期间启用错误报告。 PHP should emit a notice for an undefined variable there.
PHP应该发出一个未定义变量的通知。
Additionally, your Amp\\call
is unnecessary. 此外,您的
Amp\\call
是不必要的。 You can simply write it as: 您可以简单地将其编写为:
try {
$lead = new RequestHandler($headers, array_merge($params, $route));
$body = yield $lead->proccess();
} catch(\Exception $e){
// handle error
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.