为什么在使用register_shutdown_function()时我的“关闭回调”无效? [英] Why is my 'shutdown callback ' invalid when using register_shutdown_function()?
本文介绍了为什么在使用register_shutdown_function()时我的“关闭回调”无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
警告:register_shutdown_function():无效的关闭回调
Warning: register_shutdown_function(): Invalid shutdown callback
trait ErrorTrait {
public function shutDownFunction() {
$error = error_get_last();
// fatal error, E_ERROR === 1
if ($error['type'] === E_ERROR) {
//do your stuff
$messageStore="Using $this when not in object context";
if (strstr ( $error['message'],$messageStore))
{
echo "found it";
}
}
}
public function shutdown_function()
{
register_shutdown_function('shutDownFunction');
}
}
我在主类中使用了此特征,并从中调用函数。
I use this trait in my main class and call the functions from it
use ErrorTrait;
public function test()
{ self::shutDownFunction();
self::shutdown_function(); }
然后在这一点上,我在一个名为运行的函数中调用测试中的函数
And then at this point I call the function in test in a function called "run"
我要做的只是简单地调用该函数。
All I do is a simply call the function.
public function run()
{
self::test ();
// Rest of code}
有什么想法会引起问题吗?
Any ideas as to why this is causing problems?
推荐答案
您正在向 register_shutdown_function
中传递字符串而不是可调用字符串。调用应类似于
You are passing a string instead of a callable into register_shutdown_function
. The call should look like
register_shutdown_function([$this, 'shutDownFunction']);
这篇关于为什么在使用register_shutdown_function()时我的“关闭回调”无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文