How to display PHP errors?
P粉807397973
P粉807397973 2023-08-23 10:45:28
0
2
509
<p>I have checked my PHP ini file (<code>php.ini</code>) and set <code>display_errors</code> and the errors are reported as <code>E_ALL</code> ;. I have restarted my Apache web server. </p> <p>I even put these lines at the top of the script and it doesn't even catch simple parsing errors. For example, I declare a variable using <code>"$"</code> but do not close the statement <code>";"</code>. But all my scripts are showing a blank page on these errors, but I want to actually see the <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>What else needs to be done? </p>
P粉807397973
P粉807397973

reply all(2)
P粉203648742

You can't catch parse errors in the same file with error output enabled at runtime, because it parses the file before actually executing anything (and since it encounters errors in the meantime, it doesn'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 a .htaccess or similar file, depending on the server.

This question may provide more information.

P粉465287592

Development environment

This always works for me:

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

However, this will not make PHP show parsing errors that occur in the same file - the only way to show these errors is to modify php.ini with the following 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

Product Environment

Please note that the above suggestions only apply to development environments. On the actual website it must be

display_errors = off
log_errors = on

Then you will be able to see all errors in the error log. SeeWhere to find the PHP error log

AJAX call

If it is an AJAX call, open DevTools (F12) on the development server and open the Network tab. Then make a request for the results you want to see and it will appear in the Network tab. Click it and then click the Response tab. There you will see the exact output.
While on the live server, just check the error logs.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!