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

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

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

        在 PHP 中是否可以防止“致命错误:调用未定义的

        时间:2023-09-21

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

              <tbody id='xk2rT'></tbody>

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

            • <tfoot id='xk2rT'></tfoot>
                  <bdo id='xk2rT'></bdo><ul id='xk2rT'></ul>
                • 本文介绍了在 PHP 中是否可以防止“致命错误:调用未定义的函数"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 PHP 中,有什么方法可以忽略未定义的函数,而不是抛出在浏览器中可见的致命错误?—即,致命错误:调用未定义的函数>

                  我知道有将所有自定义函数包装在如下条件中的做法,但是有没有一种编程方式来获得这种效果?

                  if (function_exists('my_function')) {//在这里使用 my_function();}

                  解决方案

                  没有.致命错误是致命的.即使您要编写自己的错误处理程序或使用 @ 错误抑制运算符,E_FATAL 错误仍会导致脚本停止执行.

                  处理这个问题的唯一方法是使用 function_exists()(可能还有 is_callable() 为很好的措施)如上面的例子.

                  围绕潜在的(可能的?)错误进行防御性编码总是比让错误发生并在以后处理它更好的主意.

                  EDIT - php7 改变了这种行为,未定义的函数/方法是可捕获的异常.

                  In PHP, is there any way that I can ignore functions that are undefined instead of throwing a fatal error that is visible in the browser?—i.e., Fatal error: Call to undefined function

                  I know that there is the practice of wrapping all custom functions in a conditional as below, but is there a programmatic way to get this effect?

                  if (function_exists('my_function')) { 
                  
                     // use my_function() here;
                  
                  }
                  

                  解决方案

                  No. Fatal errors are fatal. Even if you were to write your own error handler or use the @ error suppression operator, E_FATAL errors will still cause the script to halt execution.

                  The only way to handle this is to use function_exists() (and possibly is_callable() for good measure) as in your example above.

                  It's always a better idea to code defensively around a potential (probable?) error than it is to just let the error happen and deal with it later anyway.

                  EDIT - php7 has changed this behavior, and undefined functions/methods are catchable exceptions.

                  这篇关于在 PHP 中是否可以防止“致命错误:调用未定义的函数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP DOMDocument 错误处理 下一篇:set_error_handler() 对致命错误不起作用

                  相关文章

                  最新文章

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

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

                  1. <tfoot id='D26vi'></tfoot>

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