Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将参数传递给专门用于register\u shutdown\u函数的可调用方法?_Php_Oop_Arguments_Callable - Fatal编程技术网

Php 如何将参数传递给专门用于register\u shutdown\u函数的可调用方法?

Php 如何将参数传递给专门用于register\u shutdown\u函数的可调用方法?,php,oop,arguments,callable,Php,Oop,Arguments,Callable,我有方法,在这个方法中可能会发生致命的错误,为了捕捉这个错误我做了这个 class a { function shutDownFunction() { $error = error_get_last(); if ($error['type'] == 1) { echo "this is fatal error"; } } function terribleFunction () {

我有方法,在这个方法中可能会发生致命的错误,为了捕捉这个错误我做了这个

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

    }


}

好的,这是可以理解的,但我需要将参数从
terribleFunction
传递到
shutDownFunction
。怎么做这个

首先需要指定
shutDownFunction
应接受一个参数

功能关闭功能($var)

然后,您可以调用
寄存器\u关闭\u函数

register\u shutdown\u函数(数组($this,'shutdownFunction'),$myVar)


文档是完整的,注释中有一些示例。

您应该只使用一个register\u shutdown\u函数,而不是仅在方法内部使用它来捕获该方法中的错误。对于错误捕获,请使用try、catch、finally块

见: 您可以查看文档。还有第二个可选参数
parameter
,它被传递给您的
关闭函数()
。您可以这样定义此函数:

function shutDownFunction($args) {
   //do whatever you want with $args
}

也许你也在寻找,你不能抓住致命的错误。它们之所以致命是有原因的。