0

we have forbidden to show errors on our server. But I'd need to show the errors in my script despite it.

I tried this:

<?php
    error_reporting(E_ALL);
    ini_set("display_errors", "on");
    echo "chyba"
    echo "nazdárek";
?>

But it is not useful. Thank you for your help.

5
  • 1. Your opening tag is missing a < at the start 2. What's your question? Commented Apr 17, 2015 at 11:41
  • What does that mean, it is not useful? Commented Apr 17, 2015 at 11:42
  • It is not functional. I can't see errors Commented Apr 17, 2015 at 11:53
  • @Rizier123 Only mistake made by copying my script to this page. Corrected. Commented Apr 17, 2015 at 11:54
  • See this would work stackoverflow.com/a/21429652/2334975 Commented Apr 17, 2015 at 13:20

2 Answers 2

1

Your call to error_reporting() doesn't do anything because it does not run.

There is a missing ; after the first echo. I know you know about it, you made the mistake on purpose, to show that error_reporting() doesn't do what you expect it to do.

It doesn't work this way. The missing semicolumn is a syntax error. The script does not compile, so it does not run. Your call to error_reporting() is not executed and that means the value of the error_reporting configuration directive is the one that decides what errors are reported.

You have to fix the syntax errors first, make the script compile & run, and only after that try to trigger a runtime error and see if it is reported back to you. I bet it is.

A runtime error or warning is easy to generate. Try a division by zero, for example.

Sign up to request clarification or add additional context in comments.

2 Comments

I know what are you meaning, but I needed to show for example: Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in... Because I don't have access to php.ini on our server and need to show my syntax mistakes.
You don't need to put the files on the live server to check them for syntax errors. Install PHP on your development computer and use php -l to check the script for errors.
0

What you're trying to produce there is a syntax error. This won't work within the same file that you're setting error reporting. The file first needs to be parsed in its entirety. If there's a syntax error in the file, then none of its code will be executed, so no error reporting will be switched on.

7 Comments

So I can't do that it wrotes me for example this one? Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in
Not within the same file. If you put your error_reporting instructions in one file and then include another file with syntax errors, it'll work.
What a pity. I have no access to php.ini to turn mistakes on, so I thought to do it in my script. Something like ignore php.ini and show me my errors.
You may be able to override PHP settings in an .htaccess file with php_flag directives. Google around a bit.
But honestly, syntax errors are things you should be catching in your local editor/IDE before they even touch your server. If you're uploading files which don't even compile there's something wrong with your workflow that you should fix.
|

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.