search

Home  >  Q&A  >  body text

How to solve PHP error display problems

<p>I have checked my PHP ini file (<code>php.ini</code>) and <code>display_errors</code> is set and error reporting is also <code>E_ALL</ code>. I have restarted my Apache web server. </p> <p>I even put these lines at the top of my script, but it doesn't even catch simple parsing errors. For example, I declare a variable with <code>"$"</code>, but I don't have the closing statement <code>";"</code>. But all the scripts display a blank page on these errors, but I would like to actually see <strong>errors</strong> in the browser output. </p> <pre class="brush:php;toolbar:false;">error_reporting(E_ALL); ini_set('display_errors', 1);</pre> <p>Is there anything else that needs to be done? </p>
P粉469090753P粉469090753491 days ago608

reply all(2)I'll reply

  • P粉604507867

    P粉6045078672023-08-21 10:46:45

    You can't catch parse errors in the same file with runtime error output enabled, because it parses the file before actually executing anything (and since it encounters errors along the way, it won't execute anything). You need to change the actual server configuration so that display_errors is turned on and the appropriate error_reporting level is used. If you don't have access to php.ini, you might be able to use .htaccess or similar, depending on the server.

    This question may provide additional information.

    reply
    0
  • P粉691461301

    P粉6914613012023-08-21 00:29:27

    Development environment

    This always works for me:

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

    However, this does not make PHP show parsing errors that occur in the same file - the only way to show these errors is to modify your php.ini file to add this line:

    display_errors = on

    (If you don't have access to php.ini, putting this line in .htaccess may also work):

    php_flag display_errors 1

    Production Environment

    Please note that the above suggestions only apply to development environments. In a production environment this must be set to:

    display_errors = off
    log_errors = on

    Then you can see all the errors in the error log. See Where to find the PHP error log

    AJAX call

    For AJAX calls, open DevTools (F12) on the development server and select the Network tab. Then make the request you want to see the results of and it will appear in the Network tab. Click on it and select the Response tab. There you will see the exact output.
    On the production server, just check the error log.

    reply
    0
  • Cancelreply