PHP5:为什么try / catch失败? [英] PHP5: Why is try/catch failing?

查看:110
本文介绍了PHP5:为什么try / catch失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的XAMPP / Win XP构建中,PHP5.2.3无法捕获任何异常。 示例都不起作用,而且:

On my XAMPP/Win XP build, PHP5.2.3 fails to catch any exceptions. None of the examples work, and this:

try {
    throw new Exception('Fail');
} catch (Exception $e) {
    echo 'Succeed';
}

...结果:


致命错误:未捕获的异常
'Exception',消息在
中显示为'Fail'M:Mpath\to\ \test.php:4堆栈跟踪:#0
{main}放在 M:\path\to\test.php 中,在 4行上

Fatal error: Uncaught exception 'Exception' with message 'Fail' in M:\path\to\test.php:4 Stack trace: #0 {main} thrown in M:\path\to\test.php on line 4

所有PHP的错误设置似乎都是标准的。服务器为Apache / 2.2.4

All of PHP's error settings seem standard. Server is Apache/2.2.4

推荐答案

这取决于XAMPP中 eAccelerator的版本。在某一时刻,它有难以优化try / catch语句,而忽略了它们。

This depends on eAccelerator's build in XAMPP. At one point, it had trouble optimizing try/catch statements and just ignored them.

问题出在0.9.5。 XAMPP当前与eAccelerator 0.9.5.3捆绑在一起,尽管默认情况下它已禁用。因此,这可能不是您的问题。

The problem was in 0.9.5. XAMPP currently is bundled with eAccelerator 0.9.5.3, although it is disabled by default. So this might not be your issue.

根据 ChangeLog ,XAMPP在很长一段时间内都没有使用过PHP 5.2.3和Apache 2.2.4,这也是eAccelerator错误发生的时间。我建议检查您的eAccelerator版本,并可能升级XAMPP。

According to the ChangeLog, XAMPP hasn't used PHP 5.2.3 and Apache 2.2.4 in a LONG time, which is also around the time of the eAccelerator bug. I recommend checking your eAccelerator version and possibly upgrading XAMPP.

这篇关于PHP5:为什么try / catch失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆