gpt4 book ai didi

php - 如何将参数传递给专门用于 register_shutdown_function 的可调用方法?

转载 作者:可可西里 更新时间:2023-11-01 13:43:14 26 4
gpt4 key购买 nike

我有方法,在这个方法中可能会发生 fatal error ,为了捕获这个错误我做了这个

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 应该接受一个参数。

函数 shutDownFunction($var)

然后你可以这样调用register_shutdown_function

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

文档是 here评论里有例子。

关于php - 如何将参数传递给专门用于 register_shutdown_function 的可调用方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13703065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com