PHP&“未发现异常". [英] PHP "Exception not found"
问题描述
我有一个有趣的问题.试图理解为什么某个网站向浏览器返回http代码500时,我发现了消息
I have a somehow funny issue. While trying to understand why a certain website returns http code 500 to browser, I found the message
PHP Fatal error: Class 'MZ\\MailChimpBundle\\Services\\Exception' not found in /var/www/website/vendor/bundles/MZ/MailChimpBundle/Services/MailChimp.php on line 41
在Apache日志中.看上面提到的那一行:
in apache log. Looking at the mentioned line:
throw new Exception('This bundle needs the cURL PHP extension.');
我现在了解了如何使站点正常工作,但是我仍然想知道引发异常的代码(会导致更有用的日志消息)为什么失败了.可能是什么原因?
I now understand how to get the site working, but I still wonder why the code for throwing the exception (which would have resulted in a more helpful log message) failed. What could be the reason?
推荐答案
MZMailChimpBundle 不包含在 MZ \ MailChimpBundle \ Services
名称空间中名为 Exception
的类.
The MZMailChimpBundle does not contain a class named Exception
within the MZ\MailChimpBundle\Services
namespace.
由于这个简单的事实,并且由于异常应该发出的错误消息与集成问题(检查curl库)有关,因此我认为这是一个错误.
Because of that simple fact and as the error message that the exception should signal is related to an integration problem (check for the curl library) I assume that this is a bug.
原文是 \ Exception
的意思,而不是 Exception
的意思.这是名称空间可能会发生的一个常见错误.要修复文件,请别名/将 \ Exception
导入为 Exception
:
The original has meant \Exception
and not Exception
here. It's a somewhat common mistake that can happen with namespaces. To fix the file, either alias/import \Exception
as Exception
:
namespace MZ\MailChimpBundle\Services;
use Exception;
和/或更改 MZMailChimpBundle/Services/MailChimp.php
:
and/or change the new
line in MZMailChimpBundle/Services/MailChimp.php
:
throw new \Exception('This bundle needs the cURL PHP extension.');
还请参见相关问题:如何使用php的根"命名空间?以及具有相同名称的那个找不到类'Namespace \ Example'错误消息:从PHP中另一个命名空间中的类调用静态方法.
See as well the related question: How to use "root" namespace of php? and the one with the same Class 'Namespace\Example' not found error message: Calling a static method from a class in another namespace in PHP.
这篇关于PHP&“未发现异常".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!