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

后端 未结 6 1994
鱼传尺愫
鱼传尺愫 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 17:59

    In php 7, this is now possible.

    Example codez:

    try {
        some_undefined_function_or_method();
    } catch (\Error $ex) { // Error is the base class for all internal PHP error exceptions.
        var_dump($ex);
    }
    

    demo

    http://php.net/manual/en/migration70.incompatible.php

    Many fatal and recoverable fatal errors have been converted to exceptions in PHP 7. These error exceptions inherit from the Error class, which itself implements the Throwable interface (the new base interface all exceptions inherit).

提交回复
热议问题