我检查了我的PHP ini文件(PHP.ini),并设置了display_errors,错误报告也是E_ALL。我已重新启动Apache Web服务器。
我甚至把这些行放在了脚本的顶部,它甚至不能捕捉到简单的解析错误。例如,我用“$”声明变量,而不关闭语句“;”。但我的所有脚本都显示了这些错误的空白页面,但我希望在浏览器输出中看到这些错误。
error_reporting(E_ALL);
ini_set('display_errors', 1);
还有什么要做?
我检查了我的PHP ini文件(PHP.ini),并设置了display_errors,错误报告也是E_ALL。我已重新启动Apache Web服务器。
我甚至把这些行放在了脚本的顶部,它甚至不能捕捉到简单的解析错误。例如,我用“$”声明变量,而不关闭语句“;”。但我的所有脚本都显示了这些错误的空白页面,但我希望在浏览器输出中看到这些错误。
error_reporting(E_ALL);
ini_set('display_errors', 1);
还有什么要做?
当前回答
上面的代码应该可以工作:
error_reporting(E_ALL);
但是,请尝试在文件中编辑手机上的代码:
error_reporting =on
其他回答
上面的代码应该可以工作:
error_reporting(E_ALL);
但是,请尝试在文件中编辑手机上的代码:
error_reporting =on
我通常会在我的普通PHP项目中使用以下代码。
if(!defined('ENVIRONMENT')){
define('ENVIRONMENT', 'DEVELOPMENT');
}
$base_url = null;
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'DEVELOPMENT':
$base_url = 'http://localhost/product/';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
break;
case 'PRODUCTION':
$base_url = 'Production URL'; /* https://google.com */
error_reporting(E_ALL);
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 1); // Mechanism to log errors
break;
default:
exit('The application environment is not set correctly.');
}
}
在index.php文件中设置:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
您可以添加自己的自定义错误处理程序,它可以提供额外的调试信息。此外,您可以将其设置为通过电子邮件向您发送信息。
function ERR_HANDLER($errno, $errstr, $errfile, $errline){
$msg = "<b>Something bad happened.</b> [$errno] $errstr <br><br>
<b>File:</b> $errfile <br>
<b>Line:</b> $errline <br>
<pre>".json_encode(debug_backtrace(), JSON_PRETTY_PRINT)."</pre> <br>";
echo $msg;
return false;
}
function EXC_HANDLER($exception){
ERR_HANDLER(0, $exception->getMessage(), $exception->getFile(), $exception->getLine());
}
function shutDownFunction() {
$error = error_get_last();
if ($error["type"] == 1) {
ERR_HANDLER($error["type"], $error["message"], $error["file"], $error["line"]);
}
}
set_error_handler ("ERR_HANDLER", E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
register_shutdown_function("shutdownFunction");
set_exception_handler("EXC_HANDLER");
您可以执行以下操作:
在主索引文件中设置以下参数:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
然后根据您的要求,您可以选择要显示的内容:
对于所有错误、警告和通知:
error_reporting(E_ALL); OR error_reporting(-1);
对于所有错误:
error_reporting(E_ERROR);
对于所有警告:
error_reporting(E_WARNING);
对于所有通知:
error_reporting(E_NOTICE);
有关详细信息,请查看此处。