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
的类。 / code>名称空间。
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
:
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;
和/或更改 new
行 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的根命名空间?,并且找不到具有相同 Class'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屋!