This question already has an answer here:
-
How to get useful error messages in PHP?
29 answers
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!
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.
You can try error_reporting(-1)
-1 is the maximum value error_reporting
can take and always will be.
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
I had this problem and fixed it by editing /etc/php.ini to display_errors = On
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.
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.