致命错误,因为传递的是 Error 实例而不是预期的 Exception 实例

2022-01-14 00:00:00 xampp php apache cakephp cakephp-3.2

我刚刚安装了带有 php 7.0.4 的 xampp 和一个新的 cakephp 3.2.6.我做了很多研究,发现的一切都表明它们是兼容的.

I just installed xampp with php 7.0.4 and a fresh cakephp 3.2.6. I did a lot of research and everything I found shows that they are compatible.

但是,一旦我用浏览器打开应用程序,蛋糕就会回复内部错误.

However as soon as I go to open the application with a browser, cake replies with an Internal Error.

唯一的指示是 xampp 在 apache error.log 中记录以下内容:

The only pointer as to what to do is that xampp logs the following in apache error.log:

PHP 致命错误:未捕获的 TypeError:传递给 CakeErrorBaseErrorHandler::handleException() 的参数 1 必须是 Exception 的实例,D:Xampphtdocscakephpvendorcakephpcakephp 中给出的错误实例srcErrorBaseErrorHandler.php:153
堆栈跟踪:
#0 [内部函数]:CakeErrorBaseErrorHandler->handleException(Object(Error))
#1 {main} 在第 153 行的 D:XampphtdocscakephpvendorcakephpcakephpsrcErrorBaseErrorHandler.php 中抛出

PHP Fatal error: Uncaught TypeError: Argument 1 passed to CakeErrorBaseErrorHandler::handleException() must be an instance of Exception, instance of Error given in D:XampphtdocscakephpvendorcakephpcakephpsrcErrorBaseErrorHandler.php:153
Stack trace:
#0 [internal function]: CakeErrorBaseErrorHandler->handleException(Object(Error))
#1 {main} thrown in D:XampphtdocscakephpvendorcakephpcakephpsrcErrorBaseErrorHandler.php on line 153

我尝试了 php 5.6 但它仍然在日志中显示错误.

I tried php 5.6 but it still shows the error in the log.

推荐答案

如果这是您遇到的错误,那么我怀疑您使用的是 CakePHP 3.2.6,因为第 153 行在评论中间

If that's the error that you are encountering, then I'd doubt that you are using CakePHP 3.2.6, as line 153 is in the middle of a comment

https://github.com/cakephp/cakephp/blob/3.2.6/src/Error/BaseErrorHandler.php#L153

从 CakePHP 3.1.5 开始处理 PHP7 错误,因此请检查您的 CakePHP 依赖项,并确保它实际上是最新的.

PHP7 errors are handled since CakePHP 3.1.5, so check your CakePHP dependency, and make sure it's actually up to date.

相关文章