简体   繁体   English

为什么使用Aerys出现“错误:在null上调用成员函数end()”?

[英]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.

相关问题 为什么我在加载 pdo 时收到“呼叫成员 function prepare() on null”? - Why am I getting 'call to a member function prepare() on null' when loading pdo? 为什么我在上传文件时在我的日志中收到“call to member function null”? - Why am I getting a “call to member function null” in my logs when file uploading? 为什么会出现“致命错误:在非对象上调用成员函数fetch_assoc()”? - Why am I getting a “Fatal error: Call to a member function fetch_assoc() on a non-object”? 为什么我会收到“在非对象上调用成员 function”错误? - Why am I getting a “Call to a member function on a non-object” error? 为什么会收到“未捕获的错误:在null上调用成员函数getFbPage()”? - Why I get “Uncaught Error: Call to a member function getFbPage() on null”? 在 null 错误时调用成员函数 prepare() - getting Call to a member function prepare() on null error 为什么会得到:为此递归函数在非对象上调用成员函数fetch_assoc()? - Why am I getting: Call to a member function fetch_assoc() on a non-object for this recursive function? PHP-为什么会出现此错误? 调用未定义的函数 - PHP - Why am I getting this error? Call to undefined function 为什么从 Controller 到库 ZC15C4252674C1683 的调用在 CodeIgniter 中出现“调用成员 function on null”错误? - Why do I get “Call to a member function on null” error in CodeIgniter with call from Controller to Library function? 我遇到了未捕获的错误:我在PHP中提交表单时在null错误上调用成员函数isSMTP() - I'm getting Uncaught Error: Call to a member function isSMTP() on null Error on my Submission of the Form in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM