【问题标题】:Localhost - PHP Include Not Showing Errors本地主机 - PHP 包括不显示错误
【发布时间】:2020-06-13 21:13:12
【问题描述】:

我刚刚安装了最新版本的 Appserv ( 9.3.0 ),其中包括:

Apache 2.4.41
PHP 7.3.10
MySQL 8.0.17
phpMyAdmin 4.9.1

我正在使用 Localhost 作为我的根目录并尝试重用旧文件来构建新网站,但我注意到了一个问题。

我正在使用include()函数,但是有问题。

<?php include(file.php); ?> 显示file.php 的内容,但是,如果我删除file.php,它不会给我一个错误消息说file.php could not be found。这是为什么呢?

【问题讨论】:

  • 您是否在服务器上启用了错误报告和显示?你检查过服务器错误日志吗?
  • 我不知道。我有一个旧版本的 appserv,一切正常,这个新版本没有达到我的预期。如何启用错误报告?
  • 这能回答你的问题吗? How do I get PHP errors to display?
  • 不是真的 @jrswgtr - 最合乎逻辑的似乎是在 php.ini 中设置 display_errors = on,但我已经尝试过了,但它仍然无法正常工作。
  • 忽略它。我删除了error_reporting(1);,它现在工作正常。

标签: php include localhost directoryindex


【解决方案1】:

第二个答案:

include() 在不存在的文件上会产生 E_WARNING 类型的错误。出于测试目的,只需添加这行代码

error_reporting(1);

在使用include() 语句之前。

对于生产,您应该避免显示任何类型的错误。您可以使用set_error_handler() 注册自己的错误处理程序。

set_error_handler(function ($no, $err, $file, $line)
{
    // do whatever you want to if an error of type E_WARNING occurs
}, E_WARNING);

【讨论】:

  • 谢谢。我在 include 语句之前添加了error_reporting(1);,但它仍然没有给我错误消息。
  • 尝试添加:ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
  • 更新:我编辑了我的 php.ini 文件,现在可以正常工作了。关于我的第一个问题有什么想法吗?
【解决方案2】:

在 Windows 10 中,转到:

Start > Appserv > PHP Edit php.ini

查找线路:display_errors Off 并更改为 display_errors On

Save & Close

Start > AppServ > Apache Restart

【讨论】:

    猜你喜欢
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2016-07-29
    相关资源
    最近更新 更多