<small id='wGGiI'></small><noframes id='wGGiI'>

    <legend id='wGGiI'><style id='wGGiI'><dir id='wGGiI'><q id='wGGiI'></q></dir></style></legend>
    1. <tfoot id='wGGiI'></tfoot>

    2. <i id='wGGiI'><tr id='wGGiI'><dt id='wGGiI'><q id='wGGiI'><span id='wGGiI'><b id='wGGiI'><form id='wGGiI'><ins id='wGGiI'></ins><ul id='wGGiI'></ul><sub id='wGGiI'></sub></form><legend id='wGGiI'></legend><bdo id='wGGiI'><pre id='wGGiI'><center id='wGGiI'></center></pre></bdo></b><th id='wGGiI'></th></span></q></dt></tr></i><div id='wGGiI'><tfoot id='wGGiI'></tfoot><dl id='wGGiI'><fieldset id='wGGiI'></fieldset></dl></div>

        <bdo id='wGGiI'></bdo><ul id='wGGiI'></ul>

      如何在 PHP 中捕获 require() 或 include() 的错误?

      时间:2023-09-21
      1. <legend id='Wmo2K'><style id='Wmo2K'><dir id='Wmo2K'><q id='Wmo2K'></q></dir></style></legend>
          <i id='Wmo2K'><tr id='Wmo2K'><dt id='Wmo2K'><q id='Wmo2K'><span id='Wmo2K'><b id='Wmo2K'><form id='Wmo2K'><ins id='Wmo2K'></ins><ul id='Wmo2K'></ul><sub id='Wmo2K'></sub></form><legend id='Wmo2K'></legend><bdo id='Wmo2K'><pre id='Wmo2K'><center id='Wmo2K'></center></pre></bdo></b><th id='Wmo2K'></th></span></q></dt></tr></i><div id='Wmo2K'><tfoot id='Wmo2K'></tfoot><dl id='Wmo2K'><fieldset id='Wmo2K'></fieldset></dl></div>

          <small id='Wmo2K'></small><noframes id='Wmo2K'>

            <bdo id='Wmo2K'></bdo><ul id='Wmo2K'></ul>

                <tbody id='Wmo2K'></tbody>
              <tfoot id='Wmo2K'></tfoot>

              • 本文介绍了如何在 PHP 中捕获 require() 或 include() 的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在用 PHP5 编写一个需要某些文件代码的脚本.当 A 文件不可用于包含时,首先会引发警告,然后会引发致命错误.当无法包含代码时,我想打印自己的错误消息.如果 requeire 不起作用,是否可以执行最后一个命令?以下方法无效:

                I'm writing a script in PHP5 that requires the code of certain files. When A file is not available for inclusion, first a warning and then a fatal error are thrown. I'd like to print an own error message, when it was not possible to include the code. Is it possible to execute one last command, if requeire did not work? the following did not work:

                require('fileERROR.php5') or die("Unable to load configuration file.");
                

                使用 error_reporting(0) 抑制所有错误消息只会产生白屏,不使用 error_reporting 会产生 PHP 错误,我不想显示.

                Supressing all error messages using error_reporting(0) only gives a white screen, not using error_reporting gives the PHP-Errors, which I don't want to show.

                推荐答案

                您可以使用 set_error_handlerErrorException.

                You can accomplish this by using set_error_handler in conjunction with ErrorException.

                ErrorException 页面中的示例是:

                <?php
                function exception_error_handler($errno, $errstr, $errfile, $errline ) {
                    throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
                }
                set_error_handler("exception_error_handler");
                
                /* Trigger exception */
                strpos();
                ?>
                

                一旦您将错误作为异常处理,您可以执行以下操作:

                Once you have errors being handled as exceptions you can do something like:

                <?php
                try {
                    include 'fileERROR.php5';
                } catch (ErrorException $ex) {
                    echo "Unable to load configuration file.";
                    // you can exit or die here if you prefer - also you can log your error,
                    // or any other steps you wish to take
                }
                ?>
                

                这篇关于如何在 PHP 中捕获 require() 或 include() 的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么以及如何在此示例 PHP 代码中使用异常? 下一篇:如何在mysql数据库连接中使用抛出异常

                相关文章

                最新文章

                  <bdo id='6JwKS'></bdo><ul id='6JwKS'></ul>
                <legend id='6JwKS'><style id='6JwKS'><dir id='6JwKS'><q id='6JwKS'></q></dir></style></legend>

                <tfoot id='6JwKS'></tfoot>

                    <small id='6JwKS'></small><noframes id='6JwKS'>

                  1. <i id='6JwKS'><tr id='6JwKS'><dt id='6JwKS'><q id='6JwKS'><span id='6JwKS'><b id='6JwKS'><form id='6JwKS'><ins id='6JwKS'></ins><ul id='6JwKS'></ul><sub id='6JwKS'></sub></form><legend id='6JwKS'></legend><bdo id='6JwKS'><pre id='6JwKS'><center id='6JwKS'></center></pre></bdo></b><th id='6JwKS'></th></span></q></dt></tr></i><div id='6JwKS'><tfoot id='6JwKS'></tfoot><dl id='6JwKS'><fieldset id='6JwKS'></fieldset></dl></div>