Not displaying PHP errors [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-05 00:08:20

问题


I've boiled down the problem and made it clean so that it hopefully will be easier for you to help me.

I have a very simple code:

<?php
echo "Hello world";
?>

This runs perfectly fine.

If I run the following code (parse error) I do not get any errors but the text "Hello world" is still displayed:

<?php
echo "Hello world";
piwejfoiwjefoijwef
?>

If I place the parse error before the code it does however not display "Hello world":

<?php
piwejfoiwjefoijwef
echo "Hello world";
?>

When I print phpinfo (in the same file, same directory) I have the following settings: display_errors On display_startup_errors On error_reporting 1

If I try to also set the error reporting inside the script and run it with the following code I still do not get any errors or warning but the text "Hello world" is displayed:

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE); ini_set('display_errors', '1');
echo "Hello world";
owieufpowiejf
?>

My php.ini file has the following values (and I have restarted Apache):

error_reporting = E_ERROR & ~E_DEPRECATED
display_errors = On
display_startup_errors = On

I am running Apache / PHP / MySQL on the Amazon AMI with on a 64-bit AWS EC2. I am not that knowledgeable with server configurations. The errors started when I transitioned to the Amazon server. Besides error reporting the server and Apache/PHP runs flawlessly.

Please guide me in what I can do to fix the problem.

Thanks!


回答1:


That is a notice.

error_reporting(E_ALL);

reveals it.

Code I used:

<?php

    error_reporting(E_ALL); ini_set('display_errors', '1');
    echo "Hello world";
    owieufpowiejf

?>

Output:

Hello world

Notice: Use of undefined constant owieufpowiejf - assumed 'owieufpowiejf' in /code/14B4LY on line 5

That's because it's not a parse error, it thinks of it as a constant and tried to parse it as a string. And placing a normal string is a valid statement.




回答2:


You can try error_reporting(-1)

-1 is the maximum value error_reporting can take and always will be.




回答3:


In your PHP script try setting error_reporting to E_ALL and see if you get a notice..

error_reporting(E_ALL)

Check out the documentation: http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting




回答4:


I had this problem and fixed it by editing /etc/php.ini to display_errors = On




回答5:


Create .htaccess file in your main directory and place:

php_flag display_errors on 
# 7 stands for E_ERROR | E_WARNING | E_PARSE
php_value error_reporting 7

Exact values of error_reporting constants could be found in the official documentation http://php.net/manual/en/errorfunc.constants.php

Of course you should have mod_rewrite enabled in your server.




回答6:


Calling error_reporting() in the same script that contains the syntax error is never going to work.

<?php
echo "Hello world";
piwejfoiwjefoijwef
?>

This script in particular does not get you any syntax error, because it does not contain any syntax error. It's just an echo statement and a bare constant in the second line. The trailing semicolon can be omitted right before the ?>

You would get a notice, if it hadn't been turned off. Again, you didn't enable E_NOTICE in your other test.



来源:https://stackoverflow.com/questions/7667160/not-displaying-php-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!