为什么 PHP 5.2.14 不显示任何错误(即使是从命令行)?

发布于 2024-09-25 08:25:22 字数 742 浏览 1 评论 0原文

我在 Windows 2008 R2 服务器和 Windows 7 64 位上安装了 PHP 5.2.10 和 PHP 5.2.14(x86 非线程安全 Win32 版本)。

由于某种原因,PHP 5.2.14 拒绝显示错误消息。

即使我在 php.ini 中设置以下设置,如果使用 5.2.14,也不会报告任何错误:

error_reporting = E_ALL
display_errors = On

即使使用 php 从命令行运行测试脚本,也会发生这种情况.exe 故意存在语法错误:

c:\php>php test.php

PHP 使用正确的 php.ini 文件,因为当我运行 php.exe -i 时我可以看到我的设置发生变化

我还注意到 PHP 5.2.14 中的 php.exe 启动速度非常慢。

当我在同一台机器上使用 PHP 5.2.10 执行同一组测试时,我得到的错误消息报告得很好。

这两个 php.ini 文件都是库存文件(基于 php.ini-recommished),但带有 error_reportingdisplay_errors< /code> 设置已修改。

I have PHP 5.2.10 and PHP 5.2.14 (x86 non-threadsafe Win32 builds) installed on a Windows 2008 R2 server and on Windows 7 64 bit.

For some reason PHP 5.2.14 refuses to show error messages.

Even when I set the following settings in php.ini I don't get any errors reported if I use 5.2.14:

error_reporting = E_ALL
display_errors = On

This happens even when running a test script from the command line using php.exe with a deliberate syntax error:

c:\php>php test.php

PHP is using the correct php.ini file because I can see my settings change when I run php.exe -i.

I also notice that php.exe in PHP 5.2.14 is very slow to start up.

When I perform the same set of tests using PHP 5.2.10 on the same machines I get error messages reported just fine.

Both of the php.ini files are stock (based off of php.ini-recommended) but with the error_reporting and display_errors settings modified.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回首观望 2024-10-02 08:25:22

我发现这确实很烦人,所以这里有一个从命令行检查语法的策略:

  1. 不要加载 ini 文件。
  2. 显式打开 display_errors 和 display_startup_errors。

php -n -l -d display_errors -d display_startup_errors 路径/to/your/phpfile.php

$ php -h 
-n               No php.ini file will be used
-l               lint, syntax checking only
-d foo[=bar]     Define INI entry foo with value 'bar'

I have found this truly annoying, so here's a strategy for checking the syntax from the command line:

  1. Don't load the ini file.
  2. Turn on display_errors and display_startup_errors explicitly.

php -n -l -d display_errors -d display_startup_errors path/to/your/phpfile.php

$ php -h 
-n               No php.ini file will be used
-l               lint, syntax checking only
-d foo[=bar]     Define INI entry foo with value 'bar'
暗恋未遂 2024-10-02 08:25:22

我正在运行更高版本的 PHP (5.4.24),但这些其他答案缺少 -我在其他地方找到了 d 选项,它使 PHP 在从命令行运行时显示可理解的解析错误:

php -d display_errors test.php

这是我在谷歌上搜索的问题的最佳答案。使用 -l 运行 linter 只会告诉您“解析 foo.php 时出错”。

I'm running a later PHP (5.4.24), but these other answers lack the -d option I found exemplified elsewhere that makes PHP display intelligible parsing errors when running from the command line:

php -d display_errors test.php

This is the best answer to the question I was googling. Running the linter with -l only tells you "Errors parsing foo.php".

落花浅忆 2024-10-02 08:25:22

您可能必须启用 display_startup_errors以及:

display_startup_errors  boolean

即使打开 display_errors,也不会显示 PHP 启动序列期间发生的错误。强烈建议保持 display_startup_errors 关闭,调试除外。

您还可以尝试使用 c:\php>php -l test.php 对文件进行 lint 测试以测试语法错误。

You might have to enable display_startup_errors as well:

display_startup_errors  boolean

Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed. It's strongly recommended to keep display_startup_errors off, except for debugging.

You can also try to lint the file with c:\php>php -l test.php to test for syntax errors.

油焖大侠 2024-10-02 08:25:22

最近,我不得不处理别人的项目......无法调试,我别无选择,只能检查这一点:

error_reporting(0);

所以,检查你的源代码。搜索类似这样的内容:“error_reporting(0);”。

找到了就评论一下吧!!!

通常,您不必将其放在源代码中,而是放在 php.ini 文件中。

Lately, I had to work on someone else's project... Not being able to debug, I had no choice but to check for this:

error_reporting(0);

So, check on your source code. Search for something like this: "error_reporting(0);".

Once you've found it, comment it!!!

Normally, you don't have to put that in the source code, but in the php.ini file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文