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.

Michal Vlasák
  • 247
  • 2
  • 14

2 Answers2

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.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • 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. – Michal Vlasák Apr 17 '15 at 12:05
  • 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`](http://php.net/manual/en/features.commandline.options.php) to check the script for errors. – axiac Apr 17 '15 at 12:12
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.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • So I can't do that it wrotes me for example this one? Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in – Michal Vlasák Apr 17 '15 at 11:57
  • 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. – deceze Apr 17 '15 at 11:58
  • 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. – Michal Vlasák Apr 17 '15 at 12:00
  • You *may* be able to override PHP settings in an .htaccess file with `php_flag` directives. Google around a bit. – deceze Apr 17 '15 at 12:02
  • 2
    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. – deceze Apr 17 '15 at 12:03
  • Can you suggest me something? I use Notepad++ and that has only html highlight correction, but no correction for php syntax errors. – Michal Vlasák Apr 17 '15 at 12:23
  • And you're also not even running your files locally? Get a local web server installed, maybe a virtual machine even. Personally I'm a fan of PhpStorm, if you're willing to spend some cash. – deceze Apr 17 '15 at 12:29