Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not displaying PHP errors [duplicate]

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!

like image 351
beetree Avatar asked Oct 05 '11 20:10

beetree


2 Answers

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.

like image 123
Madara's Ghost Avatar answered Nov 07 '22 16:11

Madara's Ghost


You can try error_reporting(-1)

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

like image 3
Ole Avatar answered Nov 07 '22 18:11

Ole