why does this syntax error return HTTP error 500 when 'display_errors' is on?

前端 未结 2 927
别跟我提以往
别跟我提以往 2021-01-23 06:46

given the following script


I get the expected

相关标签:
2条回答
  • 2021-01-23 06:52

    The second code sample is an outright syntax error. This means PHP will not progress to the point of code execution and will die at parse time. Since no code is executed, the effects of the ini_set() call are not seen, so you do not get the PHP textual error indicating the problem.

    A parse error is fatal, and the web server is (rightly) set to handle PHP fatal errors with a 500 response code. Since your PHP script did not produce any output the web server will return it's default error document for the 500 condition.

    If you want to see the textual message for parse errors in the browser - and one wouldn't normally do this is production, by the way - you will need to turn error reporting on in php.ini or using a .htaccess file.

    0 讨论(0)
  • 2021-01-23 06:54

    If forcing php to show error on run time doesn't work for you, you may try other options like setting it in php.ini instead:

    error_reporting = E_ALL | E_STRICT
    display_errors: On
    

    Good Luck!

    0 讨论(0)
提交回复
热议问题