如何将参数传递给callable方法专门用于register_shutdown_function?

OTA*_*TAR 5 php oop arguments callable

我有方法,在这个方法中可能会发生致命错误,因为我抓住了这个错误

class a {


    function shutDownFunction() { 
        $error = error_get_last();
        if ($error['type'] == 1) {
            echo "this is fatal error";
        } 
    }


    function terribleFunction () {
        register_shutdown_function(array($this,'shutdownFunction'));


        // here is code, wich may causes fatal error

    }


}
Run Code Online (Sandbox Code Playgroud)

好了,这个理解,但我需要通过参数terribleFunctionshutDownFunction.怎么做到这个?

Raw*_*ode 12

首先,您需要指定shutDownFunction应接受参数.

function shutDownFunction($var)

然后,你可以调用register_shutdown_function为使

register_shutdown_function(array($this, 'shutdownFunction'), $myVar);

文档就在这里,评论中有一些例子.