error_reporting(E_ALL) 不产生错误

php
2022-08-30 12:25:08

这是我的PHP脚本 -

<?php
  error_reporting(E_ALL);
  echo('catch this -> ' ;. $thisdoesnotexist);
?>

如果要执行,这显然应该显示一些东西。

我看到的只是一个空页。为什么不工作?error_reporting(E_ALL)

<?php
  ini_set("display_errors", "1");
  error_reporting(E_ALL);
  echo('catch this -> ' ;. $thisdoesnotexist);
?>

也无济于事。我得到的只是一个空页面。

我去过和设置和.没有任何反应。php.inidisplay_errors = Ondisplay_startup_errors = On


答案 1

您的文件存在语法错误,因此您的文件未被解释,因此设置未更改,并且您有一个空白页。

您可以将文件一分为二:

文件索引.php

<?php
    ini_set("display_errors", "1");
    error_reporting(E_ALL);
    include 'error.php';

文件错误.php

<?
    echo('catch this -> ' ;. $thisdoesnotexist);

答案 2

该错误是解析错误解析器在浏览代码时抛出它,试图理解它。在分析阶段尚未执行任何代码。因此,它尚未执行该行,因此错误报告设置尚未更改。error_reporting

您无法更改具有语法错误的文件中的错误报告设置(或实际上执行任何操作)。


推荐