Is it possible in PHP to prevent “Fatal error: Call to undefined function”?

后端 未结 6 1981
鱼传尺愫
鱼传尺愫 2020-12-03 17:31

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

6条回答
  •  被撕碎了的回忆
    2020-12-03 18:01

    Prevent no. But catch and log yes, using register_shutdown_function()

    See PHP manual

    function shutDown_handler()
    {
       $last_error = error_get_last();
       //verify if shutwown is caused by an error
       if (isset ($last_error['type']) && $last_error['type'] == E_ERROR)
       {
          /*
            my activity for log or messaging
            you can use info: 
              $last_error['type'], $last_error['message'],
              $last_error['file'], $last_error['line']
              see about on the manual PHP at error_get_last()
          */
       }
    }
    
    register_shutdown_function ('shutDown_handler');
    

提交回复
热议问题