Home Backend Development PHP Problem How to output error message in php

How to output error message in php

Oct 19, 2021 am 09:52 AM
php

How to output error prompts in php: 1. Open the corresponding PHP file; 2. Add "error_reporting(E_ALL);"; 3. Output the error message through the "function cache_shutdown_error() {...}" method That’s it.

How to output error message in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php output an error message?

php output error message

error_reporting(E_ALL);
function cache_shutdown_error() {
          $_error = error_get_last();
          if ($_error && in_array($_error['type'], array(1, 4, 16, 64, 256, 4096, E_ALL)))
{
                    header("Content-Type: text/html; charset=utf-8");
                    echo '<font color=red>你的代码出错了:</font></br>';
                    echo '致命错误:' . $_error['message'] . '</br>';
                    echo '文件:' . $_error['file'] . '</br>';
                    echo '在第' . $_error['line'] . '行</br>';
                }
            }
 register_shutdown_function("cache_shutdown_error");
Copy after login

It is best to put it at the front. If an error is reported and it terminates, this method cannot be executed.

Recommended study: "PHP video tutorial

The above is the detailed content of How to output error message in php. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌