0

I have looked around and generally PHP error reporting works well, certainly when adding the 3 lines below.

But not always, for example note the line below: echo;. I would think this should output an error pointing to that line? But instead, while testing on two different servers, on one it results in an Internal Server error and on the other the page says "This page isn’t working".

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

echo ;

This happens in more situations and makes debugging a bit of a pain.

Is this expected and does error reporting indeed not always work?

Thanks, Peter

3
  • You need to distinct between errors, warnings, notices and exceptions. Commented Jul 6, 2020 at 10:03
  • Do you mean what I described above is the expected result? Because, although I would expect a proper error/warning message, the same happens when putting the echo part in try catch blocks. Even then there is no proper error message thrown, just the "This page isn’t working" message Commented Jul 6, 2020 at 16:39
  • And for me it just shows empty page. This is PHP Parse error. You will get in in the console or while linting a file (php -l file.php). It shows: PHP Parse error: syntax error, unexpected ';' in /var/www/html/d.php on line 5. As this is parsing error whatever you have in the file above was not executed, it doesnt matter you have those error settings here - the file itself is not valid php and cannot be parsed. When server runs it it gets error from php and reacts accordingly. The error message is visible in server logs. For my apache it gets logged to /var/log/apache2/error.log by default. Commented Jul 6, 2020 at 17:13

1 Answer 1

1

This is PHP Parse error. You will get in in the console or while linting a file (php -l file.php). It shows: PHP Parse error: syntax error, unexpected ';' in /var/www/html/d.php on line 5. As this is parsing error whatever you have in the file above was not executed, it doesnt matter you have those error settings here - the file itself is not valid php and cannot be parsed. When server runs it it gets error from php and reacts accordingly. The error message is visible in server logs. For my apache it gets logged to /var/log/apache2/error.log by default.

You can set this in php.ini file. Change this display_errors = Off to display_errors = On, reload apache and you will see also these errors: Parse error: syntax error, unexpected ';' in /var/www/html/d.php on line 2 even without any other code in the file. This is the file i tested it with:

<?php
echo ;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Yes, the error_log does show the PHP Parse error:... It was actually a quick fix in WHM > Software > PHP INI Editor > display_error. This was indeed disabled

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.