9

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!

beetree
  • 871
  • 2
  • 8
  • 18
  • 1
    Have you tried using E_ALL yet? Also, if you change it in your PHP config file, you might need to restart Apache. – jprofitt Oct 05 '11 at 20:17
  • It's possible that your php is logging to a file, rather than to the page being rendered. Check to see if it's logging to your apache error logs or to it's own custom log (check your php.ini config for `error_log=x`). It might be in `/var/log/apache2/error.log` or `/var/log/php/error.log` – Tom Oct 05 '11 at 20:20

6 Answers6

23

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.

Community
  • 1
  • 1
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
3

You can try error_reporting(-1)

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

greg0ire
  • 22,714
  • 16
  • 72
  • 101
Ole
  • 776
  • 7
  • 10
2

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

Tom Kincaid
  • 4,887
  • 6
  • 47
  • 72
2

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

Jake
  • 2,471
  • 15
  • 24
2

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.

The Godfather
  • 4,235
  • 4
  • 39
  • 61
Krasimir
  • 13,306
  • 3
  • 40
  • 55
1

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.

mario
  • 144,265
  • 20
  • 237
  • 291